From 3fc1bcd2b71d4325c8b3c47e0bf45365e8b7e134 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:19:53 +0200 Subject: [PATCH] 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. --- src/tier1/strtools.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/tier1/strtools.cpp b/src/tier1/strtools.cpp index 73730739..daae31bf 100644 --- a/src/tier1/strtools.cpp +++ b/src/tier1/strtools.cpp @@ -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); }