1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-26 06:28:30 +02:00

Fix font .txt files not being null-terminated

This was an oversight when we migrated to the new UTF-8 system - it
expects a null-terminated string, but the utfcpp implementation worked
with a pointer to the end of the file instead.

I also added an assert in FILESYSTEM_loadFileToMemory() so this is less
likely to happen again - because there should be no valid reason to
have a NULL pointer for the total file size, as well as not wanting a
null terminator to be added at the end of the file.
This commit is contained in:
Dav999-v 2023-03-16 18:55:46 +01:00 committed by Misa Elizabeth Kai
parent 4398861d50
commit df577c59ef
2 changed files with 7 additions and 1 deletions

View File

@ -741,6 +741,12 @@ void FILESYSTEM_loadFileToMemory(
goto fail;
}
if (len == NULL && !addnull)
{
vlog_warn("%s is loaded with len == NULL && !addnull", name);
SDL_assert(0 && "Are you sure you don't want a null terminator to be added to these loaded file contents?");
}
/* FIXME: Dumb hack to use `special/stdin.vvvvvv` here...
* This is also checked elsewhere... grep for `special/stdin`! */
if (SDL_strcmp(name, "levels/special/stdin.vvvvvv") == 0)

View File

@ -346,7 +346,7 @@ static uint8_t load_font(FontContainer* container, const char* name)
unsigned char* charmap = NULL;
if (FILESYSTEM_areAssetsInSameRealDir(name_png, name_txt))
{
FILESYSTEM_loadAssetToMemory(name_txt, &charmap, NULL, false);
FILESYSTEM_loadAssetToMemory(name_txt, &charmap, NULL, true);
}
if (charmap != NULL)
{