Code enhancement

Fix some conversion-null, nonnull-compare, unknown-pragmas, switch warnings, add initializers.

Fix #12179, close #12180
This commit is contained in:
ozone10 2022-09-15 14:45:40 +02:00 committed by Don Ho
parent fc32fbdcce
commit 1ac1b1150d
9 changed files with 63 additions and 27 deletions

View File

@ -2321,7 +2321,7 @@ void Notepad_plus::setupColorSampleBitmapsOnMainMenuItems()
bool doCheck(HMENU mainHandle, int id) bool doCheck(HMENU mainHandle, int id)
{ {
MENUITEMINFO mii; MENUITEMINFO mii{};
mii.cbSize = sizeof(MENUITEMINFO); mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_SUBMENU | MIIM_FTYPE | MIIM_ID | MIIM_STATE; 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_MAILTO:
case INTERNET_SCHEME_FILE: case INTERNET_SCHEME_FILE:
return true; 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(" "); generic_string const mySchemes = (NppParameters::getInstance()).getNppGUI()._uriSchemes + TEXT(" ");
TCHAR *p = (TCHAR *)mySchemes.c_str(); TCHAR *p = (TCHAR *)mySchemes.c_str();
@ -4581,6 +4593,13 @@ void Notepad_plus::checkUnicodeMenuItems() const
case uni16LE : id = IDM_FORMAT_UTF_16LE; break; case uni16LE : id = IDM_FORMAT_UTF_16LE; break;
case uniCookie : id = IDM_FORMAT_AS_UTF_8; break; case uniCookie : id = IDM_FORMAT_AS_UTF_8; break;
case uni8Bit : id = IDM_FORMAT_ANSI; break; case uni8Bit : id = IDM_FORMAT_ANSI; break;
case uni7Bit:
case uni16BE_NoBOM:
case uni16LE_NoBOM:
case uniEnd:
default:
break;
} }
if (encoding == -1) if (encoding == -1)
@ -5298,7 +5317,7 @@ void Notepad_plus::fullScreenToggle()
_beforeSpecialView._winPlace.length = sizeof(_beforeSpecialView._winPlace); _beforeSpecialView._winPlace.length = sizeof(_beforeSpecialView._winPlace);
::GetWindowPlacement(_pPublicInterface->getHSelf(), &_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 //Preset view area, in case something fails, primary monitor values
fullscreenArea.top = 0; fullscreenArea.top = 0;
fullscreenArea.left = 0; fullscreenArea.left = 0;
@ -5308,7 +5327,7 @@ void Notepad_plus::fullScreenToggle()
//if (_winVersion != WV_NT) //if (_winVersion != WV_NT)
{ {
HMONITOR currentMonitor; //Handle to monitor where fullscreen should go 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 //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 currentMonitor = ::MonitorFromWindow(_pPublicInterface->getHSelf(), MONITOR_DEFAULTTONEAREST); //should always be valid monitor handle
mi.cbSize = sizeof(MONITORINFO); 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 //Use _invisibleEditView to temporarily open documents to retrieve markers
Document oldDoc = _invisibleEditView.execute(SCI_GETDOCPOINTER); Document oldDoc = _invisibleEditView.execute(SCI_GETDOCPOINTER);
const int nbElem = 2; const int nbElem = 2;
DocTabView *docTab[nbElem]; DocTabView* docTab[nbElem]{};
docTab[0] = &_mainDocTab; docTab[0] = &_mainDocTab;
docTab[1] = &_subDocTab; docTab[1] = &_subDocTab;
for (size_t k = 0; k < nbElem; ++k) for (size_t k = 0; k < nbElem; ++k)
@ -6002,7 +6021,7 @@ void Notepad_plus::notifyBufferChanged(Buffer * buffer, int mask)
{ {
prepareBufferChangedDialog(buffer); prepareBufferChangedDialog(buffer);
SCNotification scnN; SCNotification scnN{};
scnN.nmhdr.code = NPPN_FILEDELETED; scnN.nmhdr.code = NPPN_FILEDELETED;
scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf(); scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf();
scnN.nmhdr.idFrom = (uptr_t)buffer->getID(); scnN.nmhdr.idFrom = (uptr_t)buffer->getID();
@ -6037,7 +6056,7 @@ void Notepad_plus::notifyBufferChanged(Buffer * buffer, int mask)
bool isDirty = buffer->isDirty(); bool isDirty = buffer->isDirty();
// To notify plugins ro status is changed // To notify plugins ro status is changed
SCNotification scnN; SCNotification scnN{};
scnN.nmhdr.hwndFrom = (void *)buffer->getID(); scnN.nmhdr.hwndFrom = (void *)buffer->getID();
scnN.nmhdr.idFrom = (uptr_t) ((isSysReadOnly || isUserReadOnly? DOCSTATUS_READONLY : 0) | (isDirty ? DOCSTATUS_BUFFERDIRTY : 0)); scnN.nmhdr.idFrom = (uptr_t) ((isSysReadOnly || isUserReadOnly? DOCSTATUS_READONLY : 0) | (isDirty ? DOCSTATUS_BUFFERDIRTY : 0));
scnN.nmhdr.code = NPPN_READONLYCHANGED; scnN.nmhdr.code = NPPN_READONLYCHANGED;
@ -6087,7 +6106,7 @@ void Notepad_plus::notifyBufferChanged(Buffer * buffer, int mask)
else if (_subEditView.getCurrentBuffer() == buffer) else if (_subEditView.getCurrentBuffer() == buffer)
_autoCompleteSub.setLanguage(buffer->getLangType()); _autoCompleteSub.setLanguage(buffer->getLangType());
SCNotification scnN; SCNotification scnN{};
scnN.nmhdr.code = NPPN_LANGCHANGED; scnN.nmhdr.code = NPPN_LANGCHANGED;
scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf(); scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf();
scnN.nmhdr.idFrom = (uptr_t)_pEditView->getCurrentBufferID(); 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(_mainDocTab.getHSelf(), NULL, FALSE);
::InvalidateRect(_subDocTab.getHSelf(), NULL, FALSE); ::InvalidateRect(_subDocTab.getHSelf(), NULL, FALSE);
SCNotification scnN; SCNotification scnN{};
scnN.nmhdr.code = NPPN_BUFFERACTIVATED; scnN.nmhdr.code = NPPN_BUFFERACTIVATED;
scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf(); scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf();
scnN.nmhdr.idFrom = (uptr_t)bufid; scnN.nmhdr.idFrom = (uptr_t)bufid;
@ -7928,8 +7947,9 @@ DWORD WINAPI Notepad_plus::backupDocument(void * /*param*/)
} }
#ifdef _MSC_VER
#pragma warning( disable : 4127 ) #pragma warning( disable : 4127 )
#endif
//-- undoStreamComment: New function to undo stream comment around or within selection end-points. //-- undoStreamComment: New function to undo stream comment around or within selection end-points.
bool Notepad_plus::undoStreamComment(bool tryBlockComment) bool Notepad_plus::undoStreamComment(bool tryBlockComment)
{ {

View File

@ -203,7 +203,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
{ {
refreshDarkMode(static_cast<bool>(wParam)); refreshDarkMode(static_cast<bool>(wParam));
// Notify plugins that Dark Mode changed // Notify plugins that Dark Mode changed
SCNotification scnN; SCNotification scnN{};
scnN.nmhdr.code = NPPN_DARKMODECHANGED; scnN.nmhdr.code = NPPN_DARKMODECHANGED;
scnN.nmhdr.hwndFrom = hwnd; scnN.nmhdr.hwndFrom = hwnd;
scnN.nmhdr.idFrom = 0; scnN.nmhdr.idFrom = 0;
@ -1553,7 +1553,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
else if (wParam == NPPMAINMENU) else if (wParam == NPPMAINMENU)
return (LRESULT)_mainMenuHandle; return (LRESULT)_mainMenuHandle;
else else
return NULL; return static_cast<LRESULT>(NULL);
} }
case NPPM_LOADSESSION: 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) for (size_t i = 0, len = _hModelessDlgs.size() ; i < len ; ++i)
{ {
if (_hModelessDlgs[i] == reinterpret_cast<HWND>(lParam)) if (_hModelessDlgs[i] == reinterpret_cast<HWND>(lParam))
return NULL; return static_cast<LRESULT>(NULL);
} }
_hModelessDlgs.push_back(reinterpret_cast<HWND>(lParam)); _hModelessDlgs.push_back(reinterpret_cast<HWND>(lParam));
@ -1749,7 +1749,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
{ {
vector<HWND>::iterator hDlg = _hModelessDlgs.begin() + i; vector<HWND>::iterator hDlg = _hModelessDlgs.begin() + i;
_hModelessDlgs.erase(hDlg); _hModelessDlgs.erase(hDlg);
return NULL; return static_cast<LRESULT>(NULL);
} }
} }
return lParam; 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) case NPPM_DMMGETPLUGINHWNDBYNAME : //(const TCHAR *windowName, const TCHAR *moduleName)
{ {
if (!lParam) if (!lParam)
return NULL; return static_cast<LRESULT>(NULL);
TCHAR *moduleName = reinterpret_cast<TCHAR *>(lParam); TCHAR *moduleName = reinterpret_cast<TCHAR *>(lParam);
TCHAR *windowName = reinterpret_cast<TCHAR *>(wParam); TCHAR *windowName = reinterpret_cast<TCHAR *>(wParam);
@ -2396,7 +2396,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
} }
} }
} }
return NULL; return static_cast<LRESULT>(NULL);
} }
case NPPM_ADDTOOLBARICON_DEPRECATED: case NPPM_ADDTOOLBARICON_DEPRECATED:

View File

@ -37,7 +37,9 @@
#define WINAPI_LAMBDA #define WINAPI_LAMBDA
#endif #endif
#ifdef _MSC_VER
#pragma comment(lib, "uxtheme.lib") #pragma comment(lib, "uxtheme.lib")
#endif
namespace NppDarkMode namespace NppDarkMode
{ {

View File

@ -25,7 +25,9 @@
#include "UserDefineDialog.h" #include "UserDefineDialog.h"
#include "WindowsDlgRc.h" #include "WindowsDlgRc.h"
#ifdef _MSC_VER
#pragma warning(disable : 4996) // for GetVersionEx() #pragma warning(disable : 4996) // for GetVersionEx()
#endif
using namespace std; using namespace std;

View File

@ -502,12 +502,12 @@ public:
/// Returns true if this node has no children. /// Returns true if this node has no children.
bool NoChildren() const { return !firstChild; } 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. 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 ( this && type == ELEMENT ) ? (TiXmlElementA*) 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 ( this && type == COMMENT ) ? (TiXmlCommentA*) 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 ( this && type == UNKNOWN ) ? (TiXmlUnknownA*) 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 ( this && type == TEXT ) ? (TiXmlTextA*) 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 ( this && type == DECLARATION ) ? (TiXmlDeclarationA*) 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; virtual TiXmlNodeA* Clone() const = 0;

View File

@ -504,12 +504,12 @@ public:
/// Returns true if this node has no children. /// Returns true if this node has no children.
bool NoChildren() const { return !firstChild; } 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. 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 ( this && type == ELEMENT ) ? (TiXmlElement*) 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 ( this && type == COMMENT ) ? (TiXmlComment*) 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 ( this && type == UNKNOWN ) ? (TiXmlUnknown*) 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 ( this && type == TEXT ) ? (TiXmlText*) 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 ( this && type == DECLARATION ) ? (TiXmlDeclaration*) 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; virtual TiXmlNode* Clone() const = 0;

View File

@ -19,7 +19,9 @@
#include "Parameters.h" #include "Parameters.h"
#include "localization.h" #include "localization.h"
#ifdef _MSC_VER
#pragma warning(disable : 4996) // for GetVersion() #pragma warning(disable : 4996) // for GetVersion()
#endif
intptr_t CALLBACK AboutDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) intptr_t CALLBACK AboutDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
{ {

View File

@ -1118,6 +1118,12 @@ intptr_t CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARA
case STATE_MACRO: case STATE_MACRO:
case STATE_USER: case STATE_USER:
return ::SendMessage(_hSelf, WM_COMMAND, IDM_BABYGRID_DELETE, 0); return ::SendMessage(_hSelf, WM_COMMAND, IDM_BABYGRID_DELETE, 0);
case STATE_MENU:
case STATE_PLUGIN:
case STATE_SCINTILLA:
default:
break;
} }
return TRUE; return TRUE;
} }

View File

@ -1149,6 +1149,10 @@ intptr_t CALLBACK DarkModeSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
case NppDarkMode::customizedTone: case NppDarkMode::customizedTone:
id = IDC_RADIO_DARKMODE_CUSTOMIZED; id = IDC_RADIO_DARKMODE_CUSTOMIZED;
break; break;
case NppDarkMode::blackTone:
default:
break;
} }
::SendDlgItemMessage(_hSelf, id, BM_SETCHECK, TRUE, 0); ::SendDlgItemMessage(_hSelf, id, BM_SETCHECK, TRUE, 0);