From 784eea3ef73f989ff71630bbaa6cd38903404feb Mon Sep 17 00:00:00 2001 From: Don HO Date: Sat, 6 Apr 2019 16:43:23 +0200 Subject: [PATCH] Remove the test of null pointer for delete Since deleting a null pointer just does nothing: https://isocpp.org/wiki/faq/freestore-mgmt#delete-handles-null --- PowerEditor/src/NppBigSwitch.cpp | 7 ++----- PowerEditor/src/Parameters.cpp | 6 ++---- PowerEditor/src/ScitillaComponent/AutoCompletion.cpp | 3 +-- PowerEditor/src/ScitillaComponent/AutoCompletion.h | 3 +-- PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp | 5 +---- .../src/ScitillaComponent/FunctionCallTip.cpp | 12 ++++-------- .../src/ScitillaComponent/ScintillaEditView.h | 3 +-- .../ClipboardHistory/clipboardHistoryPanel.cpp | 3 +-- .../ClipboardHistory/clipboardHistoryPanel.h | 3 +-- .../src/WinControls/FunctionList/functionParser.cpp | 3 +-- .../WinControls/OpenSaveFileDialog/FileDialog.cpp | 7 ++----- PowerEditor/src/WinControls/StatusBar/StatusBar.cpp | 3 +-- PowerEditor/src/WinControls/shortcut/shortcut.cpp | 3 +-- PowerEditor/src/WinControls/shortcut/shortcut.h | 3 +-- 14 files changed, 20 insertions(+), 44 deletions(-) diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index 7563a01b..6a78c167 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -1351,11 +1351,8 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa { if (not wParam || not lParam) // Clean up current session { - if (_pShortcutMapper != nullptr) - { - delete _pShortcutMapper; - _pShortcutMapper = nullptr; - } + delete _pShortcutMapper; + _pShortcutMapper = nullptr; return TRUE; } diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 99abc115..c7a36aa0 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -883,8 +883,7 @@ NppParameters::~NppParameters() bool NppParameters::reloadStylers(TCHAR* stylePath) { - if (_pXmlUserStylerDoc) - delete _pXmlUserStylerDoc; + delete _pXmlUserStylerDoc; const TCHAR* stylePathToLoad = stylePath != nullptr ? stylePath : _stylerPath.c_str(); _pXmlUserStylerDoc = new TiXmlDocument(stylePathToLoad); @@ -937,8 +936,7 @@ bool NppParameters::reloadLang() return false; } - if (_pXmlNativeLangDocA) - delete _pXmlNativeLangDocA; + delete _pXmlNativeLangDocA; _pXmlNativeLangDocA = new TiXmlDocumentA(); diff --git a/PowerEditor/src/ScitillaComponent/AutoCompletion.cpp b/PowerEditor/src/ScitillaComponent/AutoCompletion.cpp index bc6a590b..95266867 100644 --- a/PowerEditor/src/ScitillaComponent/AutoCompletion.cpp +++ b/PowerEditor/src/ScitillaComponent/AutoCompletion.cpp @@ -772,8 +772,7 @@ bool AutoCompletion::setLanguage(LangType language) { wcscat_s(path, getApiFileName()); wcscat_s(path, TEXT(".xml")); - if (_pXmlFile) - delete _pXmlFile; + delete _pXmlFile; _pXmlFile = new TiXmlDocument(path); _funcCompletionActive = _pXmlFile->LoadFile(); diff --git a/PowerEditor/src/ScitillaComponent/AutoCompletion.h b/PowerEditor/src/ScitillaComponent/AutoCompletion.h index c1a6af1b..5df03738 100644 --- a/PowerEditor/src/ScitillaComponent/AutoCompletion.h +++ b/PowerEditor/src/ScitillaComponent/AutoCompletion.h @@ -62,8 +62,7 @@ public: }; ~AutoCompletion(){ - if (_pXmlFile) - delete _pXmlFile; + delete _pXmlFile; }; bool setLanguage(LangType language); diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp index fd2a49dc..dbc7eeca 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp @@ -233,8 +233,7 @@ const int STYLING_MASK = 255; FindReplaceDlg::~FindReplaceDlg() { _tab.destroy(); - if (_pFinder) - delete _pFinder; + delete _pFinder; for (int n = static_cast(_findersOfFinder.size()) - 1; n >= 0; n--) { delete _findersOfFinder[n]; @@ -1658,8 +1657,6 @@ bool FindReplaceDlg::processFindNext(const TCHAR *txt2find, const FindOption *op delete [] pText; - - return true; } diff --git a/PowerEditor/src/ScitillaComponent/FunctionCallTip.cpp b/PowerEditor/src/ScitillaComponent/FunctionCallTip.cpp index c6190385..10a64d10 100644 --- a/PowerEditor/src/ScitillaComponent/FunctionCallTip.cpp +++ b/PowerEditor/src/ScitillaComponent/FunctionCallTip.cpp @@ -90,8 +90,7 @@ void FunctionCallTip::setLanguageXML(TiXmlElement * pXmlKeyword) reset(); // Also clear _funcName so that next getCursorFunction will call loadFunction to parse XML structure - if (_funcName) - delete [] _funcName; + delete [] _funcName; _funcName = 0; } @@ -281,10 +280,8 @@ bool FunctionCallTip::getCursorFunction() } if (!same) { //check if we need to reload data - if (_funcName) - { - delete [] _funcName; - } + delete [] _funcName; + _funcName = new TCHAR[funcToken.length+1]; wcscpy_s(_funcName, funcToken.length+1, funcToken.token); res = loadFunction(); @@ -461,8 +458,7 @@ void FunctionCallTip::reset() { void FunctionCallTip::cleanup() { reset(); - if (_funcName) - delete [] _funcName; + delete [] _funcName; _funcName = 0; _pEditView = NULL; } diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h index 6cf1c5f0..60d884df 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h @@ -206,8 +206,7 @@ public: { for (StyleMap::iterator it2(it->second->begin()) ; it2 != it->second->end() ; ++it2) { - if (it2->second._fontName != NULL) - delete [] it2->second._fontName; + delete [] it2->second._fontName; } delete it->second; } diff --git a/PowerEditor/src/WinControls/ClipboardHistory/clipboardHistoryPanel.cpp b/PowerEditor/src/WinControls/ClipboardHistory/clipboardHistoryPanel.cpp index 5fd52712..f0edcbd7 100644 --- a/PowerEditor/src/WinControls/ClipboardHistory/clipboardHistoryPanel.cpp +++ b/PowerEditor/src/WinControls/ClipboardHistory/clipboardHistoryPanel.cpp @@ -263,8 +263,7 @@ INT_PTR CALLBACK ClipboardHistoryPanel::run_dlgProc(UINT message, WPARAM wParam, catch (...) { MessageBox(_hSelf, TEXT("Cannot process this clipboard data in the history:\nThe data is too large to be treated."), TEXT("Clipboard problem"), MB_OK | MB_APPLMODAL); - if (c) - delete[] c; + delete[] c; } } } diff --git a/PowerEditor/src/WinControls/ClipboardHistory/clipboardHistoryPanel.h b/PowerEditor/src/WinControls/ClipboardHistory/clipboardHistoryPanel.h index 3293908a..ac9d85c8 100644 --- a/PowerEditor/src/WinControls/ClipboardHistory/clipboardHistoryPanel.h +++ b/PowerEditor/src/WinControls/ClipboardHistory/clipboardHistoryPanel.h @@ -49,8 +49,7 @@ public: explicit ByteArray(ClipboardData cd); ~ByteArray() { - if (_pBytes) - delete [] _pBytes; + delete [] _pBytes; _pBytes = NULL; _length = 0; }; diff --git a/PowerEditor/src/WinControls/FunctionList/functionParser.cpp b/PowerEditor/src/WinControls/FunctionList/functionParser.cpp index 796b8302..96aa4214 100644 --- a/PowerEditor/src/WinControls/FunctionList/functionParser.cpp +++ b/PowerEditor/src/WinControls/FunctionList/functionParser.cpp @@ -39,8 +39,7 @@ FunctionParsersManager::~FunctionParsersManager() delete _parsers[i]; } - if (_pXmlFuncListDoc) - delete _pXmlFuncListDoc; + delete _pXmlFuncListDoc; } bool FunctionParsersManager::init(const generic_string& xmlPath, ScintillaEditView ** ppEditView) diff --git a/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp b/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp index f81db497..f02734a7 100644 --- a/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp +++ b/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp @@ -70,11 +70,8 @@ FileDialog::FileDialog(HWND hwnd, HINSTANCE hInst) FileDialog::~FileDialog() { - if (_fileExt) - { - delete[] _fileExt; - _fileExt = NULL; - } + delete[] _fileExt; + _fileExt = NULL; } // This function set and concatenate the filter into the list box of FileDialog. diff --git a/PowerEditor/src/WinControls/StatusBar/StatusBar.cpp b/PowerEditor/src/WinControls/StatusBar/StatusBar.cpp index bc515e70..ae5dbda0 100644 --- a/PowerEditor/src/WinControls/StatusBar/StatusBar.cpp +++ b/PowerEditor/src/WinControls/StatusBar/StatusBar.cpp @@ -47,8 +47,7 @@ enum StatusBar::~StatusBar() { - if (_lpParts != nullptr) - delete[] _lpParts; + delete[] _lpParts; } diff --git a/PowerEditor/src/WinControls/shortcut/shortcut.cpp b/PowerEditor/src/WinControls/shortcut/shortcut.cpp index 8c8eb775..745e1bd8 100644 --- a/PowerEditor/src/WinControls/shortcut/shortcut.cpp +++ b/PowerEditor/src/WinControls/shortcut/shortcut.cpp @@ -502,8 +502,7 @@ void Accelerator::updateShortcuts() size_t nbUserCmd = userCommands.size(); size_t nbPluginCmd = pluginCommands.size(); - if (_pAccelArray) - delete [] _pAccelArray; + delete [] _pAccelArray; _pAccelArray = new ACCEL[nbMenu+nbMacro+nbUserCmd+nbPluginCmd]; vector incrFindAcc; diff --git a/PowerEditor/src/WinControls/shortcut/shortcut.h b/PowerEditor/src/WinControls/shortcut/shortcut.h index ae48820f..95b4814e 100644 --- a/PowerEditor/src/WinControls/shortcut/shortcut.h +++ b/PowerEditor/src/WinControls/shortcut/shortcut.h @@ -360,8 +360,7 @@ public: ::DestroyAcceleratorTable(_hIncFindAccTab); if (_hFindAccTab) ::DestroyAcceleratorTable(_hFindAccTab); - if (_pAccelArray) - delete [] _pAccelArray; + delete [] _pAccelArray; }; void init(HMENU hMenu, HWND menuParent) { _hAccelMenu = hMenu;