From e6a6748eafeb90c92045e9a4d4c146e52e08a1b7 Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Mon, 23 May 2016 21:37:21 -0700 Subject: [PATCH] Fix wxStyledTextCtrl::GetTextRangeRaw() for invalid positions Don't return garbage if the input positions are out of range, just return an empty string in this case. --- src/stc/stc.cpp | 1 + src/stc/stc.cpp.in | 1 + 2 files changed, 2 insertions(+) diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp index 1e4c609889..f630177258 100644 --- a/src/stc/stc.cpp +++ b/src/stc/stc.cpp @@ -5038,6 +5038,7 @@ wxCharBuffer wxStyledTextCtrl::GetTextRangeRaw(int startPos, int endPos) tr.lpstrText = buf.data(); tr.chrg.cpMin = startPos; tr.chrg.cpMax = endPos; + tr.lpstrText[0] = '\0'; // initialize with 0 in case the range is invalid SendMsg(SCI_GETTEXTRANGE, 0, (sptr_t)&tr); return buf; } diff --git a/src/stc/stc.cpp.in b/src/stc/stc.cpp.in index f2a1dc5fb7..3ef93376f8 100644 --- a/src/stc/stc.cpp.in +++ b/src/stc/stc.cpp.in @@ -744,6 +744,7 @@ wxCharBuffer wxStyledTextCtrl::GetTextRangeRaw(int startPos, int endPos) tr.lpstrText = buf.data(); tr.chrg.cpMin = startPos; tr.chrg.cpMax = endPos; + tr.lpstrText[0] = '\0'; // initialize with 0 in case the range is invalid SendMsg(SCI_GETTEXTRANGE, 0, (sptr_t)&tr); return buf; }