Always add null terminator when loading files

This removes the `addnull` argument from `FILESYSTEM_loadFileToMemory`
and `FILESYSTEM_loadAssetToMemory`, and makes it so a null terminator is
always appended no matter what.

This simplifies things and removes the need for callers to make the
decision about null termination and what its implications are. Then you
get cases where null termination might not happen when it should be,
such as the one df577c59ef (#947) fixed.

When FIQ added the `addnull` argument in
5862af4445 (#117), I'm guessing he did it
because he wanted to be cautious about adding the null terminator to
every file, so he only did it for XML files, which was the only case
needed at the time. But really, there's no downsides to always appending
a null terminator. In fact, it's already always done whenever the STDIN
buffer is loaded.
This commit is contained in:
Misa
2023-03-18 15:12:24 -07:00
parent fb15a0b515
commit 63bc71b796
6 changed files with 18 additions and 37 deletions

View File

@@ -349,7 +349,7 @@ static uint8_t load_font(FontContainer* container, const char* name)
{
/* The .txt can contain null bytes, but it's still null-terminated - it protects
* against incomplete sequences getting the UTF-8 decoder to read out of bounds. */
FILESYSTEM_loadAssetToMemory(name_txt, &charmap, &length, true);
FILESYSTEM_loadAssetToMemory(name_txt, &charmap, &length);
}
if (charmap != NULL)
{