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.
This commit is contained in:
@@ -544,14 +544,14 @@ void ScintillaWX::Paste() {
|
|||||||
evt.SetString(text);
|
evt.SetString(text);
|
||||||
stc->GetEventHandler()->ProcessEvent(evt);
|
stc->GetEventHandler()->ProcessEvent(evt);
|
||||||
|
|
||||||
wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(evt.GetString());
|
const wxCharBuffer buf(wx2stc(evt.GetString()));
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
// free up the old character buffer in case the text is real big
|
// free up the old character buffer in case the text is real big
|
||||||
data.SetText(wxEmptyString);
|
data.SetText(wxEmptyString);
|
||||||
text = wxEmptyString;
|
text = wxEmptyString;
|
||||||
#endif
|
#endif
|
||||||
int len = strlen(buf);
|
const size_t len = buf.length();
|
||||||
SelectionPosition selStart = sel.IsRectangular() ?
|
SelectionPosition selStart = sel.IsRectangular() ?
|
||||||
sel.Rectangular().Start() :
|
sel.Rectangular().Start() :
|
||||||
sel.Range(sel.Main()).Start();
|
sel.Range(sel.Main()).Start();
|
||||||
@@ -1018,8 +1018,8 @@ void ScintillaWX::DoMiddleButtonUp(Point pt) {
|
|||||||
if (gotData) {
|
if (gotData) {
|
||||||
wxString text = wxTextBuffer::Translate(data.GetText(),
|
wxString text = wxTextBuffer::Translate(data.GetText(),
|
||||||
wxConvertEOLMode(pdoc->eolMode));
|
wxConvertEOLMode(pdoc->eolMode));
|
||||||
wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
|
const wxCharBuffer buf(wx2stc(text));
|
||||||
int len = strlen(buf);
|
const size_t len = buf.length();
|
||||||
int caretMain = sel.MainCaret();
|
int caretMain = sel.MainCaret();
|
||||||
pdoc->InsertString(caretMain, buf, len);
|
pdoc->InsertString(caretMain, buf, len);
|
||||||
SetEmptySelection(caretMain + len);
|
SetEmptySelection(caretMain + len);
|
||||||
@@ -1042,8 +1042,8 @@ void ScintillaWX::DoAddChar(int key) {
|
|||||||
wxChar wszChars[2];
|
wxChar wszChars[2];
|
||||||
wszChars[0] = (wxChar)key;
|
wszChars[0] = (wxChar)key;
|
||||||
wszChars[1] = 0;
|
wszChars[1] = 0;
|
||||||
wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(wszChars);
|
const wxCharBuffer buf(wx2stc(wszChars));
|
||||||
AddCharUTF((char*)buf.data(), strlen(buf));
|
AddCharUTF(buf, buf.length());
|
||||||
#else
|
#else
|
||||||
AddChar((char)key);
|
AddChar((char)key);
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user