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
This commit is contained in:
Don HO 2019-04-06 16:43:23 +02:00
parent f55c4e3d26
commit 784eea3ef7
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E
14 changed files with 20 additions and 44 deletions

View File

@ -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 (not wParam || not lParam) // Clean up current session
{ {
if (_pShortcutMapper != nullptr) delete _pShortcutMapper;
{ _pShortcutMapper = nullptr;
delete _pShortcutMapper;
_pShortcutMapper = nullptr;
}
return TRUE; return TRUE;
} }

View File

@ -883,8 +883,7 @@ NppParameters::~NppParameters()
bool NppParameters::reloadStylers(TCHAR* stylePath) bool NppParameters::reloadStylers(TCHAR* stylePath)
{ {
if (_pXmlUserStylerDoc) delete _pXmlUserStylerDoc;
delete _pXmlUserStylerDoc;
const TCHAR* stylePathToLoad = stylePath != nullptr ? stylePath : _stylerPath.c_str(); const TCHAR* stylePathToLoad = stylePath != nullptr ? stylePath : _stylerPath.c_str();
_pXmlUserStylerDoc = new TiXmlDocument(stylePathToLoad); _pXmlUserStylerDoc = new TiXmlDocument(stylePathToLoad);
@ -937,8 +936,7 @@ bool NppParameters::reloadLang()
return false; return false;
} }
if (_pXmlNativeLangDocA) delete _pXmlNativeLangDocA;
delete _pXmlNativeLangDocA;
_pXmlNativeLangDocA = new TiXmlDocumentA(); _pXmlNativeLangDocA = new TiXmlDocumentA();

View File

@ -772,8 +772,7 @@ bool AutoCompletion::setLanguage(LangType language) {
wcscat_s(path, getApiFileName()); wcscat_s(path, getApiFileName());
wcscat_s(path, TEXT(".xml")); wcscat_s(path, TEXT(".xml"));
if (_pXmlFile) delete _pXmlFile;
delete _pXmlFile;
_pXmlFile = new TiXmlDocument(path); _pXmlFile = new TiXmlDocument(path);
_funcCompletionActive = _pXmlFile->LoadFile(); _funcCompletionActive = _pXmlFile->LoadFile();

View File

@ -62,8 +62,7 @@ public:
}; };
~AutoCompletion(){ ~AutoCompletion(){
if (_pXmlFile) delete _pXmlFile;
delete _pXmlFile;
}; };
bool setLanguage(LangType language); bool setLanguage(LangType language);

View File

@ -233,8 +233,7 @@ const int STYLING_MASK = 255;
FindReplaceDlg::~FindReplaceDlg() FindReplaceDlg::~FindReplaceDlg()
{ {
_tab.destroy(); _tab.destroy();
if (_pFinder) delete _pFinder;
delete _pFinder;
for (int n = static_cast<int32_t>(_findersOfFinder.size()) - 1; n >= 0; n--) for (int n = static_cast<int32_t>(_findersOfFinder.size()) - 1; n >= 0; n--)
{ {
delete _findersOfFinder[n]; delete _findersOfFinder[n];
@ -1658,8 +1657,6 @@ bool FindReplaceDlg::processFindNext(const TCHAR *txt2find, const FindOption *op
delete [] pText; delete [] pText;
return true; return true;
} }

View File

@ -90,8 +90,7 @@ void FunctionCallTip::setLanguageXML(TiXmlElement * pXmlKeyword)
reset(); reset();
// Also clear _funcName so that next getCursorFunction will call loadFunction to parse XML structure // Also clear _funcName so that next getCursorFunction will call loadFunction to parse XML structure
if (_funcName) delete [] _funcName;
delete [] _funcName;
_funcName = 0; _funcName = 0;
} }
@ -281,10 +280,8 @@ bool FunctionCallTip::getCursorFunction()
} }
if (!same) if (!same)
{ //check if we need to reload data { //check if we need to reload data
if (_funcName) delete [] _funcName;
{
delete [] _funcName;
}
_funcName = new TCHAR[funcToken.length+1]; _funcName = new TCHAR[funcToken.length+1];
wcscpy_s(_funcName, funcToken.length+1, funcToken.token); wcscpy_s(_funcName, funcToken.length+1, funcToken.token);
res = loadFunction(); res = loadFunction();
@ -461,8 +458,7 @@ void FunctionCallTip::reset() {
void FunctionCallTip::cleanup() { void FunctionCallTip::cleanup() {
reset(); reset();
if (_funcName) delete [] _funcName;
delete [] _funcName;
_funcName = 0; _funcName = 0;
_pEditView = NULL; _pEditView = NULL;
} }

View File

@ -206,8 +206,7 @@ public:
{ {
for (StyleMap::iterator it2(it->second->begin()) ; it2 != it->second->end() ; ++it2) 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; delete it->second;
} }

View File

@ -263,8 +263,7 @@ INT_PTR CALLBACK ClipboardHistoryPanel::run_dlgProc(UINT message, WPARAM wParam,
catch (...) 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); 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;
} }
} }
} }

View File

@ -49,8 +49,7 @@ public:
explicit ByteArray(ClipboardData cd); explicit ByteArray(ClipboardData cd);
~ByteArray() { ~ByteArray() {
if (_pBytes) delete [] _pBytes;
delete [] _pBytes;
_pBytes = NULL; _pBytes = NULL;
_length = 0; _length = 0;
}; };

View File

@ -39,8 +39,7 @@ FunctionParsersManager::~FunctionParsersManager()
delete _parsers[i]; delete _parsers[i];
} }
if (_pXmlFuncListDoc) delete _pXmlFuncListDoc;
delete _pXmlFuncListDoc;
} }
bool FunctionParsersManager::init(const generic_string& xmlPath, ScintillaEditView ** ppEditView) bool FunctionParsersManager::init(const generic_string& xmlPath, ScintillaEditView ** ppEditView)

View File

@ -70,11 +70,8 @@ FileDialog::FileDialog(HWND hwnd, HINSTANCE hInst)
FileDialog::~FileDialog() 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. // This function set and concatenate the filter into the list box of FileDialog.

View File

@ -47,8 +47,7 @@ enum
StatusBar::~StatusBar() StatusBar::~StatusBar()
{ {
if (_lpParts != nullptr) delete[] _lpParts;
delete[] _lpParts;
} }

View File

@ -502,8 +502,7 @@ void Accelerator::updateShortcuts()
size_t nbUserCmd = userCommands.size(); size_t nbUserCmd = userCommands.size();
size_t nbPluginCmd = pluginCommands.size(); size_t nbPluginCmd = pluginCommands.size();
if (_pAccelArray) delete [] _pAccelArray;
delete [] _pAccelArray;
_pAccelArray = new ACCEL[nbMenu+nbMacro+nbUserCmd+nbPluginCmd]; _pAccelArray = new ACCEL[nbMenu+nbMacro+nbUserCmd+nbPluginCmd];
vector<ACCEL> incrFindAcc; vector<ACCEL> incrFindAcc;

View File

@ -360,8 +360,7 @@ public:
::DestroyAcceleratorTable(_hIncFindAccTab); ::DestroyAcceleratorTable(_hIncFindAccTab);
if (_hFindAccTab) if (_hFindAccTab)
::DestroyAcceleratorTable(_hFindAccTab); ::DestroyAcceleratorTable(_hFindAccTab);
if (_pAccelArray) delete [] _pAccelArray;
delete [] _pAccelArray;
}; };
void init(HMENU hMenu, HWND menuParent) { void init(HMENU hMenu, HWND menuParent) {
_hAccelMenu = hMenu; _hAccelMenu = hMenu;