Add bounds check to textcase() command

This makes it so that only inputs between 1 and 255 inclusive will be
accepted. Otherwise, the command has no effect.

This is because the text case is stored as one byte in a string, and a
value of zero would be the null terminator.

We also want to minimize potential weirdness with integer wrapping if we
accept inputs from outside those bounds. While the textcase variable as
used throughout the codebase is plain unqualified `char` (which, unlike
other integers, exists in a quantum superposition of being signed and
unsigned depending on compiler, machine, and various other stuff) and so
there still might be issues there, we definitely don't want anything
higher than 255.
This commit is contained in:
Misa 2024-01-09 23:57:14 -08:00
parent 34e7b1af61
commit 67df8a9679
1 changed files with 5 additions and 1 deletions

View File

@ -2457,7 +2457,11 @@ void scriptclass::run(void)
else if (words[0] == "textcase")
{
// Used to disambiguate identical textboxes for translations (1 by default)
textcase = ss_toi(words[1]);
const int number = ss_toi(words[1]);
if (number >= 1 && number <= 255)
{
textcase = number;
}
}
else if (words[0] == "loadtext")
{