From 2b991b0243c3dccf48ed926bcb754c60846f96c1 Mon Sep 17 00:00:00 2001 From: Max Freedom Pollard <272618364+MaxFreedomPollard@users.noreply.github.com> Date: Sun, 6 Sep 2026 18:17:52 -0400 Subject: [PATCH] [rtext] Fix TextToPascal()/TextToCamel() truncating text after a separator (#6132) 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. --- src/rtext.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/rtext.c b/src/rtext.c index 08fde1a4e..aa446e400 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -2186,9 +2186,11 @@ char *TextToPascal(const char *text) if (text[j] != '_') buffer[i] = text[j]; else { - j++; + while (text[j] == '_') j++; // Skip one or more separators + if (text[j] == '\0') break; // Text ends on a separator, nothing left to copy + if ((text[j] >= 'a') && (text[j] <= 'z')) buffer[i] = text[j] - 32; - else if ((text[j] >= '0') && (text[j] <= '9')) buffer[i] = text[j]; + else buffer[i] = text[j]; // Character can not be upper-cased, copy it as is } } } @@ -2268,8 +2270,11 @@ char *TextToCamel(const char *text) if (text[j] != '_') buffer[i] = text[j]; else { - j++; + while (text[j] == '_') j++; // Skip one or more separators + if (text[j] == '\0') break; // Text ends on a separator, nothing left to copy + if ((text[j] >= 'a') && (text[j] <= 'z')) buffer[i] = text[j] - 32; + else buffer[i] = text[j]; // Character can not be upper-cased, copy it as is } } }