1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 10:09:43 +01:00

Fix reading uninitialized memory when creating Menu::levellist

Valgrind reported this.

The error here is that the buffer here is only guaranteed to be
initialized up until (and including) the null-terminator, by
SDL_snprintf(). Iterating over the entire allocated buffer is bad and I
should feel bad as the girl who wrote this code; doing that reads
uninitialized memory and passes it to SDL_tolower().

As a bonus, the iterator increment is now a preincrement instead of a
postincrement.
This commit is contained in:
Misa 2021-02-15 19:18:46 -08:00 committed by Ethan Lee
parent 3226d4f312
commit fe8d163041

View file

@ -6338,7 +6338,7 @@ void Game::createmenu( enum Menu::MenuName t, bool samemenu/*= false*/ )
}
char text[menutextbytes];
SDL_snprintf(text, sizeof(text), "%s%s", prefix, ed.ListOfMetaData[i].title.c_str());
for (size_t ii = 0; ii < SDL_arraysize(text); ii++)
for (size_t ii = 0; text[ii] != '\0'; ++ii)
{
text[ii] = SDL_tolower(text[ii]);
}