From 2d15d90e02db00196a3a22707c90bc1d03b03c82 Mon Sep 17 00:00:00 2001 From: Don HO Date: Mon, 8 Jul 2019 03:31:43 +0200 Subject: [PATCH] Fix local variable shadows outer variable issues --- PowerEditor/src/Notepad_plus.cpp | 14 ++++------- PowerEditor/src/NppIO.cpp | 24 +++++++++---------- PowerEditor/src/NppNotification.cpp | 4 ---- PowerEditor/src/Parameters.cpp | 23 +++--------------- .../WinControls/ColourPicker/WordStyleDlg.cpp | 6 ++--- .../WinControls/DockingWnd/DockingCont.cpp | 4 ++-- .../FunctionList/functionListPanel.cpp | 2 +- .../WinControls/Preference/preferenceDlg.cpp | 2 -- 8 files changed, 25 insertions(+), 54 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 1c711c564..e4a6c2a1a 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -2677,10 +2677,10 @@ void Notepad_plus::maintainIndentation(TCHAR ch) { indentAmountPrevLine = _pEditView->getLineIndent(prevLine); - auto startPos = _pEditView->execute(SCI_POSITIONFROMLINE, prevLine); - auto endPos = _pEditView->execute(SCI_GETLINEENDPOSITION, prevLine); + auto startPos2 = _pEditView->execute(SCI_POSITIONFROMLINE, prevLine); + auto endPos2 = _pEditView->execute(SCI_GETLINEENDPOSITION, prevLine); _pEditView->execute(SCI_SETSEARCHFLAGS, SCFIND_REGEXP | SCFIND_POSIX); - _pEditView->execute(SCI_SETTARGETRANGE, startPos, endPos); + _pEditView->execute(SCI_SETTARGETRANGE, startPos2, endPos2); const char braceExpr[] = "[ \t]*\\{.*"; @@ -2688,7 +2688,7 @@ void Notepad_plus::maintainIndentation(TCHAR ch) if (posFound != -1 && posFound != -2) { int end = int(_pEditView->execute(SCI_GETTARGETEND)); - if (end == endPos) + if (end == endPos2) indentAmountPrevLine += tabWidth; } } @@ -3253,7 +3253,6 @@ void Notepad_plus::dropFiles(HDROP hdrop) switchEditViewTo(MAIN_VIEW); int filesDropped = ::DragQueryFile(hdrop, 0xffffffff, NULL, 0); - BufferID lastOpened = BUFFER_INVALID; vector folderPaths; vector filePaths; @@ -3282,7 +3281,6 @@ void Notepad_plus::dropFiles(HDROP hdrop) if (isOldMode || folderPaths.size() == 0) // old mode or new mode + only files { - BufferID lastOpened = BUFFER_INVALID; for (int i = 0; i < filesDropped; ++i) { @@ -3313,10 +3311,6 @@ void Notepad_plus::dropFiles(HDROP hdrop) launchFileBrowser(folderPaths); } - if (lastOpened != BUFFER_INVALID) - { - switchToFile(lastOpened); - } ::DragFinish(hdrop); // Put Notepad_plus to forefront // May not work for Win2k, but OK for lower versions diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index a91c8c5cb..95d623e8f 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -234,8 +234,8 @@ BufferID Notepad_plus::doOpen(const generic_string& fileName, bool isRecursive, if (res == IDYES) { - bool res = MainFileManager->createEmptyFile(longFileName); - if (res) + bool isOK = MainFileManager->createEmptyFile(longFileName); + if (isOK) { isCreateFileSuccessful = true; } @@ -293,15 +293,15 @@ BufferID Notepad_plus::doOpen(const generic_string& fileName, bool isRecursive, if (buffer != BUFFER_INVALID) { - bool isSnapshotMode = (backupFileName != NULL and PathFileExists(backupFileName)); + isSnapshotMode = (backupFileName != NULL && ::PathFileExists(backupFileName)); if (isSnapshotMode) { // To notify plugins that a snapshot dirty file is loaded on startup - SCNotification scnN; - scnN.nmhdr.hwndFrom = 0; - scnN.nmhdr.idFrom = (uptr_t)buffer; - scnN.nmhdr.code = NPPN_SNAPSHOTDIRTYFILELOADED; - _pluginsManager.notify(&scnN); + SCNotification scnN2; + scnN2.nmhdr.hwndFrom = 0; + scnN2.nmhdr.idFrom = (uptr_t)buffer; + scnN2.nmhdr.code = NPPN_SNAPSHOTDIRTYFILELOADED; + _pluginsManager.notify(&scnN2); buffer->setLoadedDirty(true); } @@ -535,13 +535,13 @@ bool Notepad_plus::doSave(BufferID id, const TCHAR * filename, bool isCopy) ::GetModuleFileName(NULL, nppFullPath, MAX_PATH); generic_string args = TEXT("-multiInst"); - size_t res = (size_t)::ShellExecute(_pPublicInterface->getHSelf(), TEXT("runas"), nppFullPath, args.c_str(), TEXT("."), SW_SHOW); + size_t shellExecRes = (size_t)::ShellExecute(_pPublicInterface->getHSelf(), TEXT("runas"), nppFullPath, args.c_str(), TEXT("."), SW_SHOW); // If the function succeeds, it returns a value greater than 32. If the function fails, // it returns an error value that indicates the cause of the failure. // https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153%28v=vs.85%29.aspx - if (res < 32) + if (shellExecRes < 32) { _nativeLangSpeaker.messageBox("OpenInAdminModeFailed", _pPublicInterface->getHSelf(), @@ -579,13 +579,13 @@ bool Notepad_plus::doSave(BufferID id, const TCHAR * filename, bool isCopy) args += TEXT("\""); args += fileNamePath; args += TEXT("\""); - size_t res = (size_t)::ShellExecute(_pPublicInterface->getHSelf(), TEXT("runas"), nppFullPath, args.c_str(), TEXT("."), SW_SHOW); + size_t shellExecRes = (size_t)::ShellExecute(_pPublicInterface->getHSelf(), TEXT("runas"), nppFullPath, args.c_str(), TEXT("."), SW_SHOW); // If the function succeeds, it returns a value greater than 32. If the function fails, // it returns an error value that indicates the cause of the failure. // https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153%28v=vs.85%29.aspx - if (res < 32) + if (shellExecRes < 32) { _nativeLangSpeaker.messageBox("OpenInAdminModeFailed", _pPublicInterface->getHSelf(), diff --git a/PowerEditor/src/NppNotification.cpp b/PowerEditor/src/NppNotification.cpp index 32f231b9f..62ec92413 100644 --- a/PowerEditor/src/NppNotification.cpp +++ b/PowerEditor/src/NppNotification.cpp @@ -471,15 +471,11 @@ BOOL Notepad_plus::notify(SCNotification *notification) LPNMMOUSE lpnm = (LPNMMOUSE)notification; if (lpnm->dwItemSpec == DWORD(STATUSBAR_DOC_TYPE)) { - POINT p; - ::GetCursorPos(&p); HMENU hLangMenu = ::GetSubMenu(_mainMenuHandle, MENUINDEX_LANGUAGE); TrackPopupMenu(hLangMenu, 0, p.x, p.y, 0, _pPublicInterface->getHSelf(), NULL); } else if (lpnm->dwItemSpec == DWORD(STATUSBAR_EOF_FORMAT)) { - POINT p; - ::GetCursorPos(&p); MenuPosition & menuPos = getMenuPosition("edit-eolConversion"); HMENU hEditMenu = ::GetSubMenu(_mainMenuHandle, menuPos._x); if (!hEditMenu) diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 19a9c4177..68f6019ed 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -2836,15 +2836,7 @@ bool NppParameters::writeSettingsFilesOnCloudForThe1stTime(const generic_string if (!isOK) return false; } -/* - // session.xml: Session stock the absolute file path, it should never be on cloud - generic_string cloudSessionPath = cloudSettingsPath; - PathAppend(cloudSessionPath, TEXT("session.xml")); - if (!::PathFileExists(cloudSessionPath.c_str()) && _pXmlSessionDoc) - { - _pXmlSessionDoc->SaveFile(cloudSessionPath.c_str()); - } -*/ + // userDefineLang.xml generic_string cloudUserLangsPath = cloudSettingsPath; PathAppend(cloudUserLangsPath, TEXT("userDefineLang.xml")); @@ -2885,15 +2877,6 @@ bool NppParameters::writeSettingsFilesOnCloudForThe1stTime(const generic_string return false; } - /* - // functionList.xml - generic_string cloudFunctionListPath = cloudSettingsPath; - PathAppend(cloudFunctionListPath, TEXT("functionList.xml")); - if (!::PathFileExists(cloudFunctionListPath.c_str())) - { - - } - */ return true; } @@ -6429,8 +6412,8 @@ void NppParameters::writeStyles(LexerStylerArray & lexersStylers, StyleArray & g for (size_t x = 0; x < _pXmlExternalLexerDoc.size(); ++x) { - TiXmlNode *lexersRoot = ( _pXmlExternalLexerDoc[x]->FirstChild(TEXT("NotepadPlus")))->FirstChildElement(TEXT("LexerStyles")); - for (TiXmlNode *childNode = lexersRoot->FirstChildElement(TEXT("LexerType")); + TiXmlNode* lexersRoot2 = ( _pXmlExternalLexerDoc[x]->FirstChild(TEXT("NotepadPlus")))->FirstChildElement(TEXT("LexerStyles")); + for (TiXmlNode* childNode = lexersRoot2->FirstChildElement(TEXT("LexerType")); childNode ; childNode = childNode->NextSibling(TEXT("LexerType"))) { diff --git a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp index 07767d78c..1e6d6d047 100644 --- a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp +++ b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp @@ -834,9 +834,9 @@ void WordStyleDlg::setVisualFromStyleList() LangType lType = pNppParams->getLangIDFromStr(lexerStyler.getLexerName()); if (lType == L_TEXT) { - generic_string str = lexerStyler.getLexerName(); - str += TEXT(" is not defined in NppParameters::getLangIDFromStr()"); - printStr(str.c_str()); + generic_string lexerNameStr = lexerStyler.getLexerName(); + lexerNameStr += TEXT(" is not defined in NppParameters::getLangIDFromStr()"); + printStr(lexerNameStr.c_str()); } const TCHAR *kws = pNppParams->getWordList(lType, style._keywordClass); if (!kws) diff --git a/PowerEditor/src/WinControls/DockingWnd/DockingCont.cpp b/PowerEditor/src/WinControls/DockingWnd/DockingCont.cpp index 1054787a6..1b1fe0c59 100644 --- a/PowerEditor/src/WinControls/DockingWnd/DockingCont.cpp +++ b/PowerEditor/src/WinControls/DockingWnd/DockingCont.cpp @@ -1106,10 +1106,10 @@ void DockingCont::onSize() // get active item data - size_t iItemCnt = static_cast(::SendMessage(_hContTab, TCM_GETITEMCOUNT, 0, 0)); + size_t iItemCnt2 = static_cast(::SendMessage(_hContTab, TCM_GETITEMCOUNT, 0, 0)); // resize visible plugin windows - for (size_t iItem = 0; iItem < iItemCnt; ++iItem) + for (size_t iItem = 0; iItem < iItemCnt2; ++iItem) { tcItem.mask = TCIF_PARAM; ::SendMessage(_hContTab, TCM_GETITEM, iItem, reinterpret_cast(&tcItem)); diff --git a/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp b/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp index 91b5e59ad..6f31a6605 100644 --- a/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp +++ b/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp @@ -350,7 +350,7 @@ void FunctionListPanel::reload() if (root) { - Buffer* currentBuf = (*_ppEditView)->getCurrentBuffer(); + currentBuf = (*_ppEditView)->getCurrentBuffer(); const TCHAR *fullFilePath = currentBuf->getFullPathName(); _treeView.setItemParam(root, fullFilePath); TreeParams *previousParams = getFromStateArray(fullFilePath); diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index bd681a452..9e316039d 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -808,8 +808,6 @@ INT_PTR CALLBACK MarginsDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPa case IDC_COLONENUMBER_STATIC: { - ScintillaViewParams & svp = (ScintillaViewParams &)pNppParam->getSVP(); - NativeLangSpeaker *pNativeSpeaker = pNppParam->getNativeLangSpeaker(); generic_string strNbCol = pNativeSpeaker->getLocalizedStrFromID("edit-verticaledge-nb-col", TEXT("Nb of column:"));