From 1ac1b1150d82a9efc6e23e1b9ba7a467c1eb9604 Mon Sep 17 00:00:00 2001 From: ozone10 Date: Thu, 15 Sep 2022 14:45:40 +0200 Subject: [PATCH] Code enhancement Fix some conversion-null, nonnull-compare, unknown-pragmas, switch warnings, add initializers. Fix #12179, close #12180 --- PowerEditor/src/Notepad_plus.cpp | 38 ++++++++++++++----- PowerEditor/src/NppBigSwitch.cpp | 12 +++--- PowerEditor/src/NppDarkMode.cpp | 2 + PowerEditor/src/Parameters.cpp | 2 + PowerEditor/src/TinyXml/tinyXmlA/tinyxmlA.h | 12 +++--- PowerEditor/src/TinyXml/tinyxml.h | 12 +++--- .../src/WinControls/AboutDlg/AboutDlg.cpp | 2 + .../src/WinControls/Grid/ShortcutMapper.cpp | 6 +++ .../WinControls/Preference/preferenceDlg.cpp | 4 ++ 9 files changed, 63 insertions(+), 27 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index aacda3721..f1f9757e6 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -2321,7 +2321,7 @@ void Notepad_plus::setupColorSampleBitmapsOnMainMenuItems() bool doCheck(HMENU mainHandle, int id) { - MENUITEMINFO mii; + MENUITEMINFO mii{}; mii.cbSize = sizeof(MENUITEMINFO); mii.fMask = MIIM_SUBMENU | MIIM_FTYPE | MIIM_ID | MIIM_STATE; @@ -2741,6 +2741,18 @@ bool isUrlSchemeSupported(INTERNET_SCHEME s, TCHAR *url) case INTERNET_SCHEME_MAILTO: case INTERNET_SCHEME_FILE: return true; + + case INTERNET_SCHEME_PARTIAL: + case INTERNET_SCHEME_UNKNOWN: + case INTERNET_SCHEME_DEFAULT: + case INTERNET_SCHEME_GOPHER: + case INTERNET_SCHEME_NEWS: + case INTERNET_SCHEME_SOCKS: + case INTERNET_SCHEME_JAVASCRIPT: + case INTERNET_SCHEME_VBSCRIPT: + case INTERNET_SCHEME_RES: + default: + break; } generic_string const mySchemes = (NppParameters::getInstance()).getNppGUI()._uriSchemes + TEXT(" "); TCHAR *p = (TCHAR *)mySchemes.c_str(); @@ -4581,6 +4593,13 @@ void Notepad_plus::checkUnicodeMenuItems() const case uni16LE : id = IDM_FORMAT_UTF_16LE; break; case uniCookie : id = IDM_FORMAT_AS_UTF_8; break; case uni8Bit : id = IDM_FORMAT_ANSI; break; + + case uni7Bit: + case uni16BE_NoBOM: + case uni16LE_NoBOM: + case uniEnd: + default: + break; } if (encoding == -1) @@ -5298,7 +5317,7 @@ void Notepad_plus::fullScreenToggle() _beforeSpecialView._winPlace.length = sizeof(_beforeSpecialView._winPlace); ::GetWindowPlacement(_pPublicInterface->getHSelf(), &_beforeSpecialView._winPlace); - RECT fullscreenArea; //RECT used to calculate window fullscreen size + RECT fullscreenArea{}; //RECT used to calculate window fullscreen size //Preset view area, in case something fails, primary monitor values fullscreenArea.top = 0; fullscreenArea.left = 0; @@ -5308,7 +5327,7 @@ void Notepad_plus::fullScreenToggle() //if (_winVersion != WV_NT) { HMONITOR currentMonitor; //Handle to monitor where fullscreen should go - MONITORINFO mi; //Info of that monitor + MONITORINFO mi{}; //Info of that monitor //Caution, this will not work on windows 95, so probably add some checking of some sorts like Unicode checks, IF 95 were to be supported currentMonitor = ::MonitorFromWindow(_pPublicInterface->getHSelf(), MONITOR_DEFAULTTONEAREST); //should always be valid monitor handle mi.cbSize = sizeof(MONITORINFO); @@ -5739,7 +5758,7 @@ void Notepad_plus::getCurrentOpenedFiles(Session & session, bool includUntitledD //Use _invisibleEditView to temporarily open documents to retrieve markers Document oldDoc = _invisibleEditView.execute(SCI_GETDOCPOINTER); const int nbElem = 2; - DocTabView *docTab[nbElem]; + DocTabView* docTab[nbElem]{}; docTab[0] = &_mainDocTab; docTab[1] = &_subDocTab; for (size_t k = 0; k < nbElem; ++k) @@ -6002,7 +6021,7 @@ void Notepad_plus::notifyBufferChanged(Buffer * buffer, int mask) { prepareBufferChangedDialog(buffer); - SCNotification scnN; + SCNotification scnN{}; scnN.nmhdr.code = NPPN_FILEDELETED; scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf(); scnN.nmhdr.idFrom = (uptr_t)buffer->getID(); @@ -6037,7 +6056,7 @@ void Notepad_plus::notifyBufferChanged(Buffer * buffer, int mask) bool isDirty = buffer->isDirty(); // To notify plugins ro status is changed - SCNotification scnN; + SCNotification scnN{}; scnN.nmhdr.hwndFrom = (void *)buffer->getID(); scnN.nmhdr.idFrom = (uptr_t) ((isSysReadOnly || isUserReadOnly? DOCSTATUS_READONLY : 0) | (isDirty ? DOCSTATUS_BUFFERDIRTY : 0)); scnN.nmhdr.code = NPPN_READONLYCHANGED; @@ -6087,7 +6106,7 @@ void Notepad_plus::notifyBufferChanged(Buffer * buffer, int mask) else if (_subEditView.getCurrentBuffer() == buffer) _autoCompleteSub.setLanguage(buffer->getLangType()); - SCNotification scnN; + SCNotification scnN{}; scnN.nmhdr.code = NPPN_LANGCHANGED; scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf(); scnN.nmhdr.idFrom = (uptr_t)_pEditView->getCurrentBufferID(); @@ -6138,7 +6157,7 @@ void Notepad_plus::notifyBufferActivated(BufferID bufid, int view) ::InvalidateRect(_mainDocTab.getHSelf(), NULL, FALSE); ::InvalidateRect(_subDocTab.getHSelf(), NULL, FALSE); - SCNotification scnN; + SCNotification scnN{}; scnN.nmhdr.code = NPPN_BUFFERACTIVATED; scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf(); scnN.nmhdr.idFrom = (uptr_t)bufid; @@ -7928,8 +7947,9 @@ DWORD WINAPI Notepad_plus::backupDocument(void * /*param*/) } - +#ifdef _MSC_VER #pragma warning( disable : 4127 ) +#endif //-- undoStreamComment: New function to undo stream comment around or within selection end-points. bool Notepad_plus::undoStreamComment(bool tryBlockComment) { diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index 72de9280b..164f82314 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -203,7 +203,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa { refreshDarkMode(static_cast(wParam)); // Notify plugins that Dark Mode changed - SCNotification scnN; + SCNotification scnN{}; scnN.nmhdr.code = NPPN_DARKMODECHANGED; scnN.nmhdr.hwndFrom = hwnd; scnN.nmhdr.idFrom = 0; @@ -1553,7 +1553,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa else if (wParam == NPPMAINMENU) return (LRESULT)_mainMenuHandle; else - return NULL; + return static_cast(NULL); } case NPPM_LOADSESSION: @@ -1733,7 +1733,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa for (size_t i = 0, len = _hModelessDlgs.size() ; i < len ; ++i) { if (_hModelessDlgs[i] == reinterpret_cast(lParam)) - return NULL; + return static_cast(NULL); } _hModelessDlgs.push_back(reinterpret_cast(lParam)); @@ -1749,7 +1749,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa { vector::iterator hDlg = _hModelessDlgs.begin() + i; _hModelessDlgs.erase(hDlg); - return NULL; + return static_cast(NULL); } } return lParam; @@ -2375,7 +2375,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa case NPPM_DMMGETPLUGINHWNDBYNAME : //(const TCHAR *windowName, const TCHAR *moduleName) { if (!lParam) - return NULL; + return static_cast(NULL); TCHAR *moduleName = reinterpret_cast(lParam); TCHAR *windowName = reinterpret_cast(wParam); @@ -2396,7 +2396,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa } } } - return NULL; + return static_cast(NULL); } case NPPM_ADDTOOLBARICON_DEPRECATED: diff --git a/PowerEditor/src/NppDarkMode.cpp b/PowerEditor/src/NppDarkMode.cpp index 3efee2ba0..5aff336d4 100644 --- a/PowerEditor/src/NppDarkMode.cpp +++ b/PowerEditor/src/NppDarkMode.cpp @@ -37,7 +37,9 @@ #define WINAPI_LAMBDA #endif +#ifdef _MSC_VER #pragma comment(lib, "uxtheme.lib") +#endif namespace NppDarkMode { diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 022846d37..405d13cea 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -25,7 +25,9 @@ #include "UserDefineDialog.h" #include "WindowsDlgRc.h" +#ifdef _MSC_VER #pragma warning(disable : 4996) // for GetVersionEx() +#endif using namespace std; diff --git a/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlA.h b/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlA.h index 645c60332..a91e04342 100644 --- a/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlA.h +++ b/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlA.h @@ -502,12 +502,12 @@ public: /// Returns true if this node has no children. bool NoChildren() const { return !firstChild; } - TiXmlDocumentA* ToDocument() const { return ( this && type == DOCUMENT ) ? (TiXmlDocumentA*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. - TiXmlElementA* ToElement() const { return ( this && type == ELEMENT ) ? (TiXmlElementA*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. - TiXmlCommentA* ToComment() const { return ( this && type == COMMENT ) ? (TiXmlCommentA*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. - TiXmlUnknownA* ToUnknown() const { return ( this && type == UNKNOWN ) ? (TiXmlUnknownA*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. - TiXmlTextA* ToText() const { return ( this && type == TEXT ) ? (TiXmlTextA*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. - TiXmlDeclarationA* ToDeclaration() const { return ( this && type == DECLARATION ) ? (TiXmlDeclarationA*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlDocumentA* ToDocument() const { return ( type == DOCUMENT ) ? (TiXmlDocumentA*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlElementA* ToElement() const { return ( type == ELEMENT ) ? (TiXmlElementA*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlCommentA* ToComment() const { return ( type == COMMENT ) ? (TiXmlCommentA*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlUnknownA* ToUnknown() const { return ( type == UNKNOWN ) ? (TiXmlUnknownA*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlTextA* ToText() const { return ( type == TEXT ) ? (TiXmlTextA*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlDeclarationA* ToDeclaration() const { return ( type == DECLARATION ) ? (TiXmlDeclarationA*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. virtual TiXmlNodeA* Clone() const = 0; diff --git a/PowerEditor/src/TinyXml/tinyxml.h b/PowerEditor/src/TinyXml/tinyxml.h index 0c6f45548..10eefe2d7 100644 --- a/PowerEditor/src/TinyXml/tinyxml.h +++ b/PowerEditor/src/TinyXml/tinyxml.h @@ -504,12 +504,12 @@ public: /// Returns true if this node has no children. bool NoChildren() const { return !firstChild; } - TiXmlDocument* ToDocument() const { return ( this && type == DOCUMENT ) ? (TiXmlDocument*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. - TiXmlElement* ToElement() const { return ( this && type == ELEMENT ) ? (TiXmlElement*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. - TiXmlComment* ToComment() const { return ( this && type == COMMENT ) ? (TiXmlComment*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. - TiXmlUnknown* ToUnknown() const { return ( this && type == UNKNOWN ) ? (TiXmlUnknown*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. - TiXmlText* ToText() const { return ( this && type == TEXT ) ? (TiXmlText*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. - TiXmlDeclaration* ToDeclaration() const { return ( this && type == DECLARATION ) ? (TiXmlDeclaration*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlDocument* ToDocument() const { return ( type == DOCUMENT ) ? (TiXmlDocument*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlElement* ToElement() const { return ( type == ELEMENT ) ? (TiXmlElement*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlComment* ToComment() const { return ( type == COMMENT ) ? (TiXmlComment*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlUnknown* ToUnknown() const { return ( type == UNKNOWN ) ? (TiXmlUnknown*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlText* ToText() const { return ( type == TEXT ) ? (TiXmlText*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlDeclaration* ToDeclaration() const { return ( type == DECLARATION ) ? (TiXmlDeclaration*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. virtual TiXmlNode* Clone() const = 0; diff --git a/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp b/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp index 57725247b..cee0b1f22 100644 --- a/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp +++ b/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp @@ -19,7 +19,9 @@ #include "Parameters.h" #include "localization.h" +#ifdef _MSC_VER #pragma warning(disable : 4996) // for GetVersion() +#endif intptr_t CALLBACK AboutDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) { diff --git a/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp b/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp index c0e3d8d27..23a4d82a3 100644 --- a/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp +++ b/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp @@ -1118,6 +1118,12 @@ intptr_t CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARA case STATE_MACRO: case STATE_USER: return ::SendMessage(_hSelf, WM_COMMAND, IDM_BABYGRID_DELETE, 0); + + case STATE_MENU: + case STATE_PLUGIN: + case STATE_SCINTILLA: + default: + break; } return TRUE; } diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index f3fa07411..dbc470b64 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -1149,6 +1149,10 @@ intptr_t CALLBACK DarkModeSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA case NppDarkMode::customizedTone: id = IDC_RADIO_DARKMODE_CUSTOMIZED; break; + + case NppDarkMode::blackTone: + default: + break; } ::SendDlgItemMessage(_hSelf, id, BM_SETCHECK, TRUE, 0);