REVIEW: TextSplit()

Just adding a security check
This commit is contained in:
Ray 2019-08-19 15:09:54 +02:00
parent 12bcdb977a
commit 2f42b0ce85

View file

@ -1372,20 +1372,25 @@ const char **TextSplit(const char *text, char delimiter, int *count)
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH); memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
result[0] = buffer; result[0] = buffer;
int counter = 1; int counter = 0;
// Count how many substrings we have on text and point to every one if (text != NULL)
for (int i = 0; i < MAX_TEXT_BUFFER_LENGTH; i++)
{ {
buffer[i] = text[i]; counter = 1;
if (buffer[i] == '\0') break;
else if (buffer[i] == delimiter)
{
buffer[i] = '\0'; // Set an end of string at this point
result[counter] = buffer + i + 1;
counter++;
if (counter == MAX_SUBSTRINGS_COUNT) break; // Count how many substrings we have on text and point to every one
for (int i = 0; i < MAX_TEXT_BUFFER_LENGTH; i++)
{
buffer[i] = text[i];
if (buffer[i] == '\0') break;
else if (buffer[i] == delimiter)
{
buffer[i] = '\0'; // Set an end of string at this point
result[counter] = buffer + i + 1;
counter++;
if (counter == MAX_SUBSTRINGS_COUNT) break;
}
} }
} }