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 (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;
int start = currentSelection.cpMin;
int replacedLen = 0;
if (isRegExp)
{
replacedLen = (*_ppEditView)->replaceTargetRegExMode(pTextReplace);
replacedLen = (*_ppEditView)->replaceTargetRegExMode(txt2replace);
}
else
{
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);

View File

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

View File

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

View File

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