From e6fe568bbf83b38449306d75bb2f8ea1aa766b54 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Fri, 8 Jul 2022 17:48:46 +0200 Subject: [PATCH] Fix crash during Search result Fix #11883, close #11889 --- PowerEditor/src/NppNotification.cpp | 6 ++++++ lexilla/lexers/LexSearchResult.cxx | 8 +++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/PowerEditor/src/NppNotification.cpp b/PowerEditor/src/NppNotification.cpp index 934b78a0e..97d6b3847 100644 --- a/PowerEditor/src/NppNotification.cpp +++ b/PowerEditor/src/NppNotification.cpp @@ -963,6 +963,9 @@ BOOL Notepad_plus::notify(SCNotification *notification) { BufferID idd = _mainDocTab.getBufferByIndex(id); Buffer * buf = MainFileManager.getBufferByID(idd); + if (buf == nullptr) + return FALSE; + tipTmp = buf->getFullPathName(); if (tipTmp.length() >= tipMaxLen) @@ -975,6 +978,9 @@ BOOL Notepad_plus::notify(SCNotification *notification) { BufferID idd = _subDocTab.getBufferByIndex(id); Buffer * buf = MainFileManager.getBufferByID(idd); + if (buf == nullptr) + return FALSE; + tipTmp = buf->getFullPathName(); if (tipTmp.length() >= tipMaxLen) diff --git a/lexilla/lexers/LexSearchResult.cxx b/lexilla/lexers/LexSearchResult.cxx index 5b956f346..31b0aa440 100644 --- a/lexilla/lexers/LexSearchResult.cxx +++ b/lexilla/lexers/LexSearchResult.cxx @@ -77,8 +77,10 @@ static void ColouriseSearchResultLine(SearchResultMarkings* pMarkings, char *lin styler.ColourTo(startLine + currentPos - 1, SCE_SEARCHRESULT_LINE_NUMBER); - int currentStat = SCE_SEARCHRESULT_DEFAULT; + int currentState = SCE_SEARCHRESULT_DEFAULT; + if (linenum >= pMarkings->_length) + return; SearchResultMarkingLine miLine = pMarkings->_markings[linenum]; for (std::pair mi : miLine._segmentPostions) @@ -92,11 +94,11 @@ static void ColouriseSearchResultLine(SearchResultMarkings* pMarkings, char *lin if (match_end <= endPos) styler.ColourTo(match_end, SCE_SEARCHRESULT_WORD2SEARCH); else - currentStat = SCE_SEARCHRESULT_WORD2SEARCH; + currentState = SCE_SEARCHRESULT_WORD2SEARCH; } } - styler.ColourTo(endPos, currentStat); + styler.ColourTo(endPos, currentState); } else // every character - search header {