Tier1: properly fix V_SplitString2

Patch in commit 057a2c801a40c2f280193da9963b009adb9f75f6 was done incorrectly, causing intermittent string truncation as subtracting pFirstSeparator from pCurPos will leave with a window in the buffer of exactly that split string, but the previous patch subtracted another char from it whilst adding one in AllocString just for it to be nulled.
This commit is contained in:
Kawe Mazidjatari 2024-09-23 16:19:53 +02:00
parent 8c9d873fbe
commit 3fc1bcd2b7

View File

@ -446,14 +446,13 @@ void V_SplitString2(const char* pString, const char** pSeparators, ssize_t nSepa
if (pFirstSeparator > pCurPos)
{
const ssize_t nLen = (pFirstSeparator-1) - pCurPos;
const ssize_t nLen = pFirstSeparator - pCurPos;
char* const pSplit = AllocString(pCurPos, nLen);
// We need to terminate the array here since we copy the string
// from the list minus the delimiter, and AllocString assumes
// the null is already in the source buffer (also reserving
// space for it). therefore we need len+1 to terminate it.
pSplit[nLen + 1] = '\0';
// from the list minus the delimiter. AllocString adds 1 to len
// or the null character.
pSplit[nLen] = '\0';
outStrings.AddToTail(pSplit);
}