From e41a59ee075efda72b0cc665cda3ee3abc1616c1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 3 May 2016 16:09:11 +0200 Subject: [PATCH] Fix Unicode conversions in Scintilla code in ANSI build Don't just use wxWX2MBbuf which is just a "const char*" in ANSI build and can become a dangling pointer if the string it was constructed from was temporary, as it happens with the string returned by wxStyledTextEvent::GetString(). Closes #17517. --- src/stc/ScintillaWX.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/stc/ScintillaWX.cpp b/src/stc/ScintillaWX.cpp index aebf75b4f9..b8e5c330a6 100644 --- a/src/stc/ScintillaWX.cpp +++ b/src/stc/ScintillaWX.cpp @@ -544,14 +544,14 @@ void ScintillaWX::Paste() { evt.SetString(text); stc->GetEventHandler()->ProcessEvent(evt); - wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(evt.GetString()); + const wxCharBuffer buf(wx2stc(evt.GetString())); #if wxUSE_UNICODE // free up the old character buffer in case the text is real big data.SetText(wxEmptyString); text = wxEmptyString; #endif - int len = strlen(buf); + const size_t len = buf.length(); SelectionPosition selStart = sel.IsRectangular() ? sel.Rectangular().Start() : sel.Range(sel.Main()).Start(); @@ -1018,8 +1018,8 @@ void ScintillaWX::DoMiddleButtonUp(Point pt) { if (gotData) { wxString text = wxTextBuffer::Translate(data.GetText(), wxConvertEOLMode(pdoc->eolMode)); - wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); - int len = strlen(buf); + const wxCharBuffer buf(wx2stc(text)); + const size_t len = buf.length(); int caretMain = sel.MainCaret(); pdoc->InsertString(caretMain, buf, len); SetEmptySelection(caretMain + len); @@ -1042,8 +1042,8 @@ void ScintillaWX::DoAddChar(int key) { wxChar wszChars[2]; wszChars[0] = (wxChar)key; wszChars[1] = 0; - wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(wszChars); - AddCharUTF((char*)buf.data(), strlen(buf)); + const wxCharBuffer buf(wx2stc(wszChars)); + AddCharUTF(buf, buf.length()); #else AddChar((char)key); #endif