Browse Source

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
commit
9d09ee818a
  1. 6
      PowerEditor/src/ScintillaComponent/Buffer.cpp
  2. 11
      PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp
  3. 2
      PowerEditor/src/WinControls/TreeView/TreeView.cpp

6
PowerEditor/src/ScintillaComponent/Buffer.cpp

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

11
PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp

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

2
PowerEditor/src/WinControls/TreeView/TreeView.cpp

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

Loading…
Cancel
Save