Fix a crash by improving cutString() function

Remove an arbitrary MAX_PATH character limit

Fixes #2727, closes #4037
This commit is contained in:
Silent 2018-01-12 00:34:04 +01:00 committed by Don HO
parent 0e60bd8957
commit 7a0dae5912

View File

@ -651,38 +651,25 @@ typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
void cutString(const TCHAR* str2cut, vector<generic_string>& patternVect) void cutString(const TCHAR* str2cut, vector<generic_string>& patternVect)
{ {
TCHAR str2scan[MAX_PATH]; if (str2cut == nullptr) return;
lstrcpy(str2scan, str2cut);
size_t len = lstrlen(str2scan);
bool isProcessing = false;
TCHAR *pBegin = nullptr;
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 ' ': if (pBegin != pEnd)
case '\0': patternVect.emplace_back(pBegin, pEnd);
{ pBegin = pEnd + 1;
if (isProcessing)
{
str2scan[i] = '\0';
patternVect.push_back(pBegin);
isProcessing = false;
} }
break; ++pEnd;
} }
default: if (pBegin != pEnd)
{ patternVect.emplace_back(pBegin, pEnd);
if (!isProcessing)
{
isProcessing = true;
pBegin = str2scan+i;
}
}
}
}
} }