Fix a potential undefined behaviour & improve some codes

- init grabSize
- optimize WcharMbcsConvertor instance set
- remove unused var in TreeView::searchLeafRecusivelyAndBuildTree()
- missing nullpointer check in ScintillaEditView::init()

Close #14844
pull/14846/head
Christian Grasser 3 years ago committed by Don Ho
parent 83f0232d91
commit 9d09ee818a

@ -1054,7 +1054,7 @@ bool FileManager::backupCurrentBuffer()
else
{
WcharMbcsConvertor& wmc = WcharMbcsConvertor::getInstance();
size_t grabSize;
size_t grabSize = 0;
for (size_t i = 0; i < lengthDoc; i += grabSize)
{
grabSize = lengthDoc - i;
@ -1209,14 +1209,14 @@ SavingStatus FileManager::saveBuffer(BufferID id, const TCHAR* filename, bool is
}
else
{
WcharMbcsConvertor& wmc = WcharMbcsConvertor::getInstance();
if (lengthDoc == 0)
{
isWrittenSuccessful = UnicodeConvertor.writeFile(buf, 0);
}
else
{
size_t grabSize;
WcharMbcsConvertor& wmc = WcharMbcsConvertor::getInstance();
size_t grabSize = 0;
for (size_t i = 0; i < lengthDoc; i += grabSize)
{
grabSize = lengthDoc - i;

@ -340,11 +340,14 @@ void ScintillaEditView::init(HINSTANCE hInst, HWND hPere)
{
auto defaultCharListLen = execute(SCI_GETWORDCHARS);
char *defaultCharList = new char[defaultCharListLen + 1];
if(defaultCharList)
{
execute(SCI_GETWORDCHARS, 0, reinterpret_cast<LPARAM>(defaultCharList));
defaultCharList[defaultCharListLen] = '\0';
_defaultCharList = defaultCharList;
delete[] defaultCharList;
}
}
//Get the startup document and make a buffer for it so it can be accessed like a file
attachDefaultDoc();
}

@ -660,14 +660,12 @@ bool TreeView::searchLeafRecusivelyAndBuildTree(HTREEITEM tree2Build, const gene
}
}
size_t i = 0;
bool isOk = true;
for (HTREEITEM hItem = getChildFrom(tree2Search); hItem != NULL; hItem = getNextSibling(hItem))
{
isOk = searchLeafRecusivelyAndBuildTree(tree2Build, text2Search, index2Search, hItem);
if (!isOk)
break;
++i;
}
return isOk;
}

Loading…
Cancel
Save