From 9d09ee818a2effcb54e4e7452dbd2c377bed835b Mon Sep 17 00:00:00 2001 From: Christian Grasser Date: Sat, 25 Dec 2021 12:03:59 +0100 Subject: [PATCH] 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 --- PowerEditor/src/ScintillaComponent/Buffer.cpp | 6 +++--- .../src/ScintillaComponent/ScintillaEditView.cpp | 11 +++++++---- PowerEditor/src/WinControls/TreeView/TreeView.cpp | 2 -- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/PowerEditor/src/ScintillaComponent/Buffer.cpp b/PowerEditor/src/ScintillaComponent/Buffer.cpp index e159a85c1..dae500349 100644 --- a/PowerEditor/src/ScintillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScintillaComponent/Buffer.cpp @@ -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; diff --git a/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp index f89dede39..9af96de2e 100644 --- a/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp @@ -340,10 +340,13 @@ void ScintillaEditView::init(HINSTANCE hInst, HWND hPere) { auto defaultCharListLen = execute(SCI_GETWORDCHARS); char *defaultCharList = new char[defaultCharListLen + 1]; - execute(SCI_GETWORDCHARS, 0, reinterpret_cast(defaultCharList)); - defaultCharList[defaultCharListLen] = '\0'; - _defaultCharList = defaultCharList; - delete[] defaultCharList; + if(defaultCharList) + { + execute(SCI_GETWORDCHARS, 0, reinterpret_cast(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(); diff --git a/PowerEditor/src/WinControls/TreeView/TreeView.cpp b/PowerEditor/src/WinControls/TreeView/TreeView.cpp index c0f5ee95c..4a60a00ca 100644 --- a/PowerEditor/src/WinControls/TreeView/TreeView.cpp +++ b/PowerEditor/src/WinControls/TreeView/TreeView.cpp @@ -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; }