Fix some incoherent codes

Fixed PVS-Studio static analyser reported issues:
FindReplaceDlg.cpp: Release dynamically allocated memory.
BabyGrid.cpp: lpcs variable assigned twice successively.
ProjectPanel.cpp: A memory leak is possible.
TreeView.cpp: Wrong value is returned.

Closes #3463
This commit is contained in:
SinghRajenM 2017-07-01 18:56:40 +05:30 committed by Don HO
parent 29bbf3ce83
commit a476b885e4
4 changed files with 25 additions and 13 deletions

View File

@ -1628,29 +1628,30 @@ bool FindReplaceDlg::processReplace(const TCHAR *txt2find, const TCHAR *txt2repl
// If the next find is the same as the last, then perform the replacement // If the next find is the same as the last, then perform the replacement
if (nextFind.cpMin == currentSelection.cpMin && nextFind.cpMax == currentSelection.cpMax) if (nextFind.cpMin == currentSelection.cpMin && nextFind.cpMax == currentSelection.cpMax)
{ {
int stringSizeFind = lstrlen(txt2find);
int stringSizeReplace = lstrlen(txt2replace);
TCHAR *pTextFind = new TCHAR[stringSizeFind + 1];
TCHAR *pTextReplace = new TCHAR[stringSizeReplace + 1];
lstrcpy(pTextFind, txt2find);
lstrcpy(pTextReplace, txt2replace);
bool isRegExp = replaceOptions._searchType == FindRegex; bool isRegExp = replaceOptions._searchType == FindRegex;
int start = currentSelection.cpMin; int start = currentSelection.cpMin;
int replacedLen = 0; int replacedLen = 0;
if (isRegExp) if (isRegExp)
{ {
replacedLen = (*_ppEditView)->replaceTargetRegExMode(pTextReplace); replacedLen = (*_ppEditView)->replaceTargetRegExMode(txt2replace);
} }
else else
{ {
if (replaceOptions._searchType == FindExtended) if (replaceOptions._searchType == FindExtended)
{ {
Searching::convertExtendedToString(pTextReplace, pTextReplace, stringSizeReplace); int stringSizeReplace = lstrlen(txt2replace);
TCHAR *pText2ReplaceExtended = new TCHAR[stringSizeReplace + 1];
Searching::convertExtendedToString(txt2replace, pText2ReplaceExtended, stringSizeReplace);
replacedLen = (*_ppEditView)->replaceTarget(pText2ReplaceExtended);
delete[] pText2ReplaceExtended;
}
else
{
replacedLen = (*_ppEditView)->replaceTarget(txt2replace);
} }
replacedLen = (*_ppEditView)->replaceTarget(pTextReplace);
} }
(*_ppEditView)->execute(SCI_SETSEL, start + replacedLen, start + replacedLen); (*_ppEditView)->execute(SCI_SETSEL, start + replacedLen, start + replacedLen);

View File

@ -3104,7 +3104,6 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
} }
break; */ break; */
case WM_CREATE: case WM_CREATE:
lpcs = &cs;
lpcs = (LPCREATESTRUCT)lParam; lpcs = (LPCREATESTRUCT)lParam;
hInst = lpcs->hInstance; hInst = lpcs->hInstance;

View File

@ -323,19 +323,31 @@ bool ProjectPanel::openWorkSpace(const TCHAR *projectFileName)
TiXmlDocument *pXmlDocProject = new TiXmlDocument(projectFileName); TiXmlDocument *pXmlDocProject = new TiXmlDocument(projectFileName);
bool loadOkay = pXmlDocProject->LoadFile(); bool loadOkay = pXmlDocProject->LoadFile();
if (!loadOkay) if (!loadOkay)
{
delete pXmlDocProject;
return false; return false;
}
TiXmlNode *root = pXmlDocProject->FirstChild(TEXT("NotepadPlus")); TiXmlNode *root = pXmlDocProject->FirstChild(TEXT("NotepadPlus"));
if (!root) if (!root)
{
delete pXmlDocProject;
return false; return false;
}
TiXmlNode *childNode = root->FirstChildElement(TEXT("Project")); TiXmlNode *childNode = root->FirstChildElement(TEXT("Project"));
if (!childNode) if (!childNode)
{
delete pXmlDocProject;
return false; return false;
}
if (!::PathFileExists(projectFileName)) if (!::PathFileExists(projectFileName))
{
delete pXmlDocProject;
return false; return false;
}
_treeView.removeAllItems(); _treeView.removeAllItems();
_workSpaceFilePath = projectFileName; _workSpaceFilePath = projectFileName;

View File

@ -118,7 +118,7 @@ LPARAM TreeView::getItemParam(HTREEITEM Item2Get) const
generic_string TreeView::getItemDisplayName(HTREEITEM Item2Set) const generic_string TreeView::getItemDisplayName(HTREEITEM Item2Set) const
{ {
if (not Item2Set) if (not Item2Set)
return false; return TEXT("");
TCHAR textBuffer[MAX_PATH]; TCHAR textBuffer[MAX_PATH];
TVITEM tvItem; TVITEM tvItem;
tvItem.hItem = Item2Set; tvItem.hItem = Item2Set;