From 7a0dae5912e2c28d627b83e1aebfbc13ed3f5275 Mon Sep 17 00:00:00 2001 From: Silent Date: Fri, 12 Jan 2018 00:34:04 +0100 Subject: [PATCH] Fix a crash by improving cutString() function Remove an arbitrary MAX_PATH character limit Fixes #2727, closes #4037 --- PowerEditor/src/Parameters.cpp | 41 ++++++++++++---------------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index b545bf30..c2ba20c0 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -651,38 +651,25 @@ typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO); void cutString(const TCHAR* str2cut, vector& patternVect) { - TCHAR str2scan[MAX_PATH]; - lstrcpy(str2scan, str2cut); - size_t len = lstrlen(str2scan); - bool isProcessing = false; - TCHAR *pBegin = nullptr; + if (str2cut == nullptr) return; - for (size_t i = 0 ; i <= len ; ++i) + const TCHAR *pBegin = str2cut; + const TCHAR *pEnd = pBegin; + + while (*pEnd != '\0') { - switch(str2scan[i]) + if (_istspace(*pEnd)) { - case ' ': - case '\0': - { - if (isProcessing) - { - str2scan[i] = '\0'; - patternVect.push_back(pBegin); - isProcessing = false; - } - break; - } - - default: - { - if (!isProcessing) - { - isProcessing = true; - pBegin = str2scan+i; - } - } + if (pBegin != pEnd) + patternVect.emplace_back(pBegin, pEnd); + pBegin = pEnd + 1; + } + ++pEnd; } + + if (pBegin != pEnd) + patternVect.emplace_back(pBegin, pEnd); }