From 993506af0aff2701a40eae5e1d0f25cc650ac53b Mon Sep 17 00:00:00 2001 From: Don Ho Date: Mon, 31 Jan 2022 03:55:28 +0100 Subject: [PATCH] Fix Find in Files crash --- PowerEditor/src/MISC/Common/Common.cpp | 6 +++--- PowerEditor/src/MISC/Common/Common.h | 2 +- PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp | 4 ++-- PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp | 2 +- PowerEditor/src/ScintillaComponent/ScintillaEditView.h | 2 +- scintilla/include/Scintilla.h | 6 +++--- scintilla/lexers/LexSearchResult.cxx | 6 +++++- 7 files changed, 16 insertions(+), 12 deletions(-) diff --git a/PowerEditor/src/MISC/Common/Common.cpp b/PowerEditor/src/MISC/Common/Common.cpp index 7fee9e43f..13df546df 100644 --- a/PowerEditor/src/MISC/Common/Common.cpp +++ b/PowerEditor/src/MISC/Common/Common.cpp @@ -449,7 +449,7 @@ const char* WcharMbcsConvertor::wchar2char(const wchar_t * wcharStr2Convert, siz } -const char * WcharMbcsConvertor::wchar2char(const wchar_t * wcharStr2Convert, size_t codepage, long* mstart, long* mend) +const char * WcharMbcsConvertor::wchar2char(const wchar_t * wcharStr2Convert, size_t codepage, intptr_t* mstart, intptr_t* mend) { if (nullptr == wcharStr2Convert) return nullptr; @@ -462,8 +462,8 @@ const char * WcharMbcsConvertor::wchar2char(const wchar_t * wcharStr2Convert, si if (*mstart < lstrlenW(wcharStr2Convert) && *mend < lstrlenW(wcharStr2Convert)) { - *mstart = WideCharToMultiByte(cp, 0, wcharStr2Convert, *mstart, NULL, 0, NULL, NULL); - *mend = WideCharToMultiByte(cp, 0, wcharStr2Convert, *mend, NULL, 0, NULL, NULL); + *mstart = WideCharToMultiByte(cp, 0, wcharStr2Convert, (int)*mstart, NULL, 0, NULL, NULL); + *mend = WideCharToMultiByte(cp, 0, wcharStr2Convert, (int)*mend, NULL, 0, NULL, NULL); if (*mstart >= len || *mend >= len) { *mstart = 0; diff --git a/PowerEditor/src/MISC/Common/Common.h b/PowerEditor/src/MISC/Common/Common.h index a28e00f44..7137236df 100644 --- a/PowerEditor/src/MISC/Common/Common.h +++ b/PowerEditor/src/MISC/Common/Common.h @@ -97,7 +97,7 @@ public: const wchar_t * char2wchar(const char *mbStr, size_t codepage, int lenMbcs =-1, int* pLenOut=NULL, int* pBytesNotProcessed=NULL); const wchar_t * char2wchar(const char *mbcs2Convert, size_t codepage, intptr_t* mstart, intptr_t* mend); const char * wchar2char(const wchar_t *wcStr, size_t codepage, int lenIn = -1, int* pLenOut = NULL); - const char * wchar2char(const wchar_t *wcStr, size_t codepage, long* mstart, long* mend); + const char * wchar2char(const wchar_t *wcStr, size_t codepage, intptr_t* mstart, intptr_t* mend); const char * encode(UINT fromCodepage, UINT toCodepage, const char *txt2Encode, int lenIn = -1, int* pLenOut=NULL, int* pBytesNotProcessed=NULL) { diff --git a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp index 660ce3060..58ee97503 100644 --- a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp @@ -4065,8 +4065,8 @@ void Finder::add(FoundInfo fi, SearchResultMarking mi, const TCHAR* foundline) wsprintf(lnb, TEXT("%d"), static_cast(fi._lineNumber)); str += lnb; str += TEXT(": "); - mi._start += static_cast(str.length()); - mi._end += static_cast(str.length()); + mi._start += str.length(); + mi._end += str.length(); str += foundline; WcharMbcsConvertor& wmc = WcharMbcsConvertor::getInstance(); diff --git a/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp index 49b68ce73..197fb7d8e 100644 --- a/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp @@ -2330,7 +2330,7 @@ void ScintillaEditView::addGenericText(const TCHAR * text2Append) const execute(SCI_ADDTEXT, strlen(text2AppendA), reinterpret_cast(text2AppendA)); } -void ScintillaEditView::addGenericText(const TCHAR * text2Append, long* mstart, long* mend) const +void ScintillaEditView::addGenericText(const TCHAR * text2Append, intptr_t* mstart, intptr_t* mend) const { WcharMbcsConvertor& wmc = WcharMbcsConvertor::getInstance(); size_t cp = execute(SCI_GETCODEPAGE); diff --git a/PowerEditor/src/ScintillaComponent/ScintillaEditView.h b/PowerEditor/src/ScintillaComponent/ScintillaEditView.h index c6860fb10..38ba62c8f 100644 --- a/PowerEditor/src/ScintillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScintillaComponent/ScintillaEditView.h @@ -248,7 +248,7 @@ public: intptr_t searchInTarget(const TCHAR * Text2Find, size_t lenOfText2Find, size_t fromPos, size_t toPos) const; void appandGenericText(const TCHAR * text2Append) const; void addGenericText(const TCHAR * text2Append) const; - void addGenericText(const TCHAR * text2Append, long* mstart, long* mend) const; + void addGenericText(const TCHAR * text2Append, intptr_t* mstart, intptr_t* mend) const; intptr_t replaceTarget(const TCHAR * str2replace, intptr_t fromTargetPos = -1, intptr_t toTargetPos = -1) const; intptr_t replaceTargetRegExMode(const TCHAR * re, intptr_t fromTargetPos = -1, intptr_t toTargetPos = -1) const; void showAutoComletion(size_t lenEntered, const TCHAR * list); diff --git a/scintilla/include/Scintilla.h b/scintilla/include/Scintilla.h index f5cd312ad..201d49e00 100644 --- a/scintilla/include/Scintilla.h +++ b/scintilla/include/Scintilla.h @@ -1279,12 +1279,12 @@ struct SCNotification { }; struct SearchResultMarking { - long _start; - long _end; + intptr_t _start; + intptr_t _end; }; struct SearchResultMarkings { - long _length; + intptr_t _length; SearchResultMarking *_markings; }; diff --git a/scintilla/lexers/LexSearchResult.cxx b/scintilla/lexers/LexSearchResult.cxx index 9f5b6cc92..4e2ebe7db 100644 --- a/scintilla/lexers/LexSearchResult.cxx +++ b/scintilla/lexers/LexSearchResult.cxx @@ -104,13 +104,16 @@ static void ColouriseSearchResultDoc(Sci_PositionU startPos, Sci_Position length unsigned int linePos = 0; size_t startLine = startPos; - const char *addrMarkingsStruct = (styler.pprops)->Get("@MarkingsStruct"); + const char* addrMarkingsStruct = (styler.pprops)->Get("@MarkingsStruct"); if (!addrMarkingsStruct || !addrMarkingsStruct[0]) return; SearchResultMarkings* pMarkings = NULL; sscanf(addrMarkingsStruct, "%p", (void**)&pMarkings); + if (!pMarkings || !pMarkings->_markings) + return; + for (size_t i = startPos; i < startPos + length; i++) { lineBuffer[linePos++] = styler[i]; if (AtEOL(styler, i) || (linePos >= sizeof(lineBuffer) - 1)) { @@ -122,6 +125,7 @@ static void ColouriseSearchResultDoc(Sci_PositionU startPos, Sci_Position length while (!AtEOL(styler, i)) i++; } } + if (linePos > 0) { // Last line does not have ending characters ColouriseSearchResultLine(pMarkings, lineBuffer, startLine, startPos + length - 1, styler, styler.GetLine(startLine)); }