mirror of
https://github.com/raysan5/raylib.git
synced 2026-09-14 01:50:50 +00:00
[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.
This commit is contained in:
committed by
GitHub
parent
c64eda6377
commit
2b991b0243
11
src/rtext.c
11
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user