From da2d14436ca8a6a07b8c979bb14d099038c0cf00 Mon Sep 17 00:00:00 2001 From: Don HO Date: Sun, 24 Feb 2019 11:34:27 +0100 Subject: [PATCH] [EU-FOSSA] Enhance the macroable detection to avoid crash --- PowerEditor/src/NppCommands.cpp | 2 +- .../src/WinControls/shortcut/shortcut.cpp | 36 ++++++++++++------- .../src/WinControls/shortcut/shortcut.h | 4 +-- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index 4524067e..fc33be7e 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -54,7 +54,7 @@ void Notepad_plus::macroPlayback(Macro macro) for (Macro::iterator step = macro.begin(); step != macro.end(); ++step) { - if (step->isPlayable()) + if (step->isScintillaMacro()) step->PlayBack(this->_pPublicInterface, _pEditView); else _findReplaceDlg.execSavedCommand(step->_message, step->_lParameter, step->_sParameter); diff --git a/PowerEditor/src/WinControls/shortcut/shortcut.cpp b/PowerEditor/src/WinControls/shortcut/shortcut.cpp index a8a5d8a3..d5de34ab 100644 --- a/PowerEditor/src/WinControls/shortcut/shortcut.cpp +++ b/PowerEditor/src/WinControls/shortcut/shortcut.cpp @@ -666,26 +666,34 @@ recordedMacroStep::recordedMacroStep(int iMessage, uptr_t wParam, uptr_t lParam, // code comes from Scintilla's Editor.cxx: // void Editor::NotifyMacroRecord(unsigned int iMessage, uptr_t wParam, sptr_t lParam) -bool recordedMacroStep::isMacroable(unsigned int iMessage) +bool recordedMacroStep::isMacroable() const { // Enumerates all macroable messages - switch (iMessage) + switch (_message) { + case SCI_REPLACESEL: // (, const char *text) + case SCI_ADDTEXT: // (int length, const char *s) + case SCI_INSERTTEXT: // (int pos, const char *text) + case SCI_APPENDTEXT: // (int length, const char *s) + case SCI_SEARCHNEXT: // (int searchFlags, const char *text) + case SCI_SEARCHPREV: // (int searchFlags, const char *text) + { + if (_macroType == mtUseSParameter) + return true; + else + return false; + } + + case SCI_GOTOLINE: // (int line) + case SCI_GOTOPOS: // (int position) + case SCI_SETSELECTIONMODE: // (int mode) case SCI_CUT: case SCI_COPY: case SCI_PASTE: case SCI_CLEAR: - case SCI_REPLACESEL: - case SCI_ADDTEXT: - case SCI_INSERTTEXT: - case SCI_APPENDTEXT: case SCI_CLEARALL: case SCI_SELECTALL: - case SCI_GOTOLINE: - case SCI_GOTOPOS: case SCI_SEARCHANCHOR: - case SCI_SEARCHNEXT: - case SCI_SEARCHPREV: case SCI_LINEDOWN: case SCI_LINEDOWNEXTEND: case SCI_PARADOWN: @@ -761,7 +769,6 @@ bool recordedMacroStep::isMacroable(unsigned int iMessage) case SCI_HOMEDISPLAYEXTEND: case SCI_LINEENDDISPLAY: case SCI_LINEENDDISPLAYEXTEND: - case SCI_SETSELECTIONMODE: case SCI_LINEDOWNRECTEXTEND: case SCI_LINEUPRECTEXTEND: case SCI_CHARLEFTRECTEXTEND: @@ -778,7 +785,12 @@ bool recordedMacroStep::isMacroable(unsigned int iMessage) case SCI_MOVESELECTEDLINESDOWN: case SCI_SCROLLTOSTART: case SCI_SCROLLTOEND: - return true; + { + if (_macroType == mtUseLParameter) + return true; + else + return false; + } // Filter out all others like display changes. Also, newlines are redundant // with char insert messages. diff --git a/PowerEditor/src/WinControls/shortcut/shortcut.h b/PowerEditor/src/WinControls/shortcut/shortcut.h index 0c23075a..8faac433 100644 --- a/PowerEditor/src/WinControls/shortcut/shortcut.h +++ b/PowerEditor/src/WinControls/shortcut/shortcut.h @@ -300,8 +300,8 @@ struct recordedMacroStep { bool isValid() const { return true; }; - bool isPlayable() const {return _macroType <= mtMenuCommand;}; - bool isMacroable(unsigned int iMessage); + bool isScintillaMacro() const {return _macroType <= mtMenuCommand;}; + bool isMacroable() const; void PlayBack(Window* pNotepad, ScintillaEditView *pEditView); };