diff options
| author | Ray <[email protected]> | 2019-08-19 15:09:54 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2019-08-19 15:09:54 +0200 |
| commit | 2f42b0ce857ff07ad8a9b50e1a2c24bf0d8bf3c1 (patch) | |
| tree | 14fa866df119101993cfe90cc0676e72864a8ecc | |
| parent | 12bcdb977a15a4db933765b3cf4af205a492c8b2 (diff) | |
| download | raylib-2f42b0ce857ff07ad8a9b50e1a2c24bf0d8bf3c1.tar.gz raylib-2f42b0ce857ff07ad8a9b50e1a2c24bf0d8bf3c1.zip | |
REVIEW: TextSplit()
Just adding a security check
| -rw-r--r-- | src/text.c | 27 |
1 files changed, 16 insertions, 11 deletions
@@ -1372,20 +1372,25 @@ const char **TextSplit(const char *text, char delimiter, int *count) memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH); result[0] = buffer; - int counter = 1; - - // Count how many substrings we have on text and point to every one - for (int i = 0; i < MAX_TEXT_BUFFER_LENGTH; i++) + int counter = 0; + + if (text != NULL) { - buffer[i] = text[i]; - if (buffer[i] == '\0') break; - else if (buffer[i] == delimiter) + counter = 1; + + // 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] = '\0'; // Set an end of string at this point - result[counter] = buffer + i + 1; - counter++; + 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; + if (counter == MAX_SUBSTRINGS_COUNT) break; + } } } |
