[rtext] Fix TextSplit() reading past its buffer on text of 1024 bytes or more (#6136)

The copy loop filled all MAX_TEXT_BUFFER_LENGTH bytes, so the last substring
could come back with no terminator, and a delimiter on the last byte made
buffers[] point one past the end of the array. Stop one byte earlier so the
zero left by the memset() at the top of the function always terminates the
last substring.
This commit is contained in:
Max Freedom Pollard
2026-09-10 09:13:05 -04:00
committed by GitHub
parent f25c8241f3
commit 94a69ad9e2

View File

@@ -2082,7 +2082,8 @@ char **TextSplit(const char *text, char delimiter, int *count)
counter = 1;
// Count how many substrings ar found on text and set pointers to every one
for (int i = 0; i < MAX_TEXT_BUFFER_LENGTH; i++)
// NOTE: Last buffer byte is reserved to terminate the last substring
for (int i = 0; i < MAX_TEXT_BUFFER_LENGTH - 1; i++)
{
buffer[i] = text[i];
if (buffer[i] == '\0') break;