From fefdbc9cad7bbe4f505adf184147e7daae29a73f Mon Sep 17 00:00:00 2001 From: Don HO Date: Thu, 3 Dec 2020 18:13:25 +0100 Subject: [PATCH] Fix command line arguments -p, -n & -c negative value's undefined behaviour The negative values of these 3 arguments won't be undefined anymore. They will be rejected - so negative values are just ignored. Fix #9146 --- PowerEditor/src/Notepad_plus.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index f77dadc5..cd69e14a 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -5896,9 +5896,9 @@ std::vector Notepad_plus::loadCommandlineParams(const TCHAR * co } LangType lt = pCmdParams->_langType; - int ln = pCmdParams->_line2go; - int cn = pCmdParams->_column2go; - int cpos = pCmdParams->_pos2go; + int lineNumber = pCmdParams->_line2go; + int columnNumber = pCmdParams->_column2go; + int positionNumber = pCmdParams->_pos2go; bool recursive = pCmdParams->_isRecursive; bool readOnly = pCmdParams->_isReadOnly; bool openFoldersAsWorkspace = pCmdParams->_openFoldersAsWorkspace; @@ -5928,30 +5928,30 @@ std::vector Notepad_plus::loadCommandlineParams(const TCHAR * co pBuf->setLangType(lt); } - if (ln != -1 || cpos != -1) + if (lineNumber >= 0 || positionNumber >= 0) { //we have to move the cursor manually int iView = currentView(); //store view since fileswitch can cause it to change switchToFile(bufID); //switch to the file. No deferred loading, but this way we can easily move the cursor to the right position - if (cpos != -1) + if (positionNumber >= 0) { - if (cpos > 0) + if (positionNumber > 0) { // make sure not jumping into the middle of a multibyte character // or into the middle of a CR/LF pair for Windows files - auto before = _pEditView->execute(SCI_POSITIONBEFORE, cpos); - cpos = static_cast(_pEditView->execute(SCI_POSITIONAFTER, before)); + auto before = _pEditView->execute(SCI_POSITIONBEFORE, positionNumber); + positionNumber = static_cast(_pEditView->execute(SCI_POSITIONAFTER, before)); } - _pEditView->execute(SCI_GOTOPOS, cpos); + _pEditView->execute(SCI_GOTOPOS, positionNumber); } - else if (cn == -1) + else if (columnNumber < 0) { - _pEditView->execute(SCI_GOTOLINE, ln-1); + _pEditView->execute(SCI_GOTOLINE, lineNumber - 1); } else { - auto pos = _pEditView->execute(SCI_FINDCOLUMN, ln-1, cn-1); + auto pos = _pEditView->execute(SCI_FINDCOLUMN, lineNumber - 1, columnNumber - 1); _pEditView->execute(SCI_GOTOPOS, pos); }