[rtext] Fix TextToPascal()/TextToCamel() truncating text after a separator - #6132
Merged
raysan5 merged 1 commit intoSep 6, 2026
Merged
Conversation
…rator
Both functions walk the input with two indexes and, on hitting '_', advance
j once and only write buffer[i] when the next character is one they know how
to handle. TextToPascal() (src/rtext.c:2186) covers 'a'-'z' and '0'-'9',
TextToCamel() (src/rtext.c:2270) covers only 'a'-'z'. Anything else leaves
buffer[i] at the zero it was memset to, so the returned string ends there
and the rest of the text is silently dropped: TextToPascal("text_UTF8_load")
returned "Text" and TextToCamel("sound_3d_mix") returned "sound".
The same path also reads past the end of the string. When '_' is the last
character, j++ lands on the '\0', neither branch matches, and then the loop
increment moves j one further before the condition reads text[j], one byte
beyond the terminator.
Skip the whole run of separators instead, stop when it reaches the end of
the text, and copy any character that has no upper case form as it is.
Owner
|
@MaxFreedomPollard thanks for the review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TextToPascal()andTextToCamel()drop everything after an underscore unless the character right after it is one they explicitly handle.TextToPascal()(src/rtext.c:2186) handlesa-zand0-9,TextToCamel()(src/rtext.c:2270) handles onlya-z. For anything else neither branch runs,buffer[i]keeps the zero from thememset()at the top of the function, and the returned string ends right there.So
TextToPascal("text_UTF8_load")returns"Text", andTextToCamel("sound_3d_mix")returns"sound". An upper case letter after the separator truncates both, a digit after the separator truncatesTextToCamel(), and two underscores in a row truncate both.The same code also reads one byte past the string. When
_is the last character,j++lands on the\0, neither branch matches, and then the loop increment movesjone further before the condition readstext[j].This skips the whole run of separators, stops when that reaches the end of the text, and copies a character that has no upper case form as it is. That last
elsealso covers digits, so it replaces the0-9branchTextToPascal()had.Verified at a2cc9b1 on macOS arm64 with Apple clang 17, CMake configured with
-DBUILD_EXAMPLES=ON. The program below links against the builtlibraylib.aand opens no window. Before the change:After:
The last check writes
"hello_"so its\0is the final byte of a readable page with an unreadable page right behind it, which is why the read past the terminator shows up as a crash rather than as a wrong string.TextToPascal("raylib_fun_videogames_programming")andTextToCamel("raylib_fun_videogames_programming")from examples/text/text_strings_management.c are unchanged, andTextToSnake()is not touched. The library and 225 examples build clean, and so do tools/rlparser and tools/rexm.