commit 309441792880e0fd0633b45348582ea191ca6788
parent 0c67a66b11bbb3e7832a2384e5b865d3feb5e0c7
Author: Chris Bracken <chris@bracken.jp>
Date: Fri, 6 Mar 2026 17:37:06 +0900
fs: fix binary file truncation in inmemory_fopen
When opening a file for reading, use the stored file size instead of
strlen. Since binary files can contain null bytes, strlen would
incorrectly truncate the file content, causing read operations to return
incomplete data.
This is purely test code, but should still fix it.
Diffstat:
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/fs_inmemory.c b/src/fs_inmemory.c
@@ -57,7 +57,7 @@ static FILE* inmemory_fopen(const char* path, const char* mode) {
for (size_t i = 0; i < g_files_count; i++) {
if (strcmp(g_files[i].path, path) == 0) {
if (g_files[i].buf) {
- FILE* f = fmemopen(g_files[i].buf, strlen(g_files[i].buf), "r");
+ FILE* f = fmemopen(g_files[i].buf, g_files[i].size, "r");
if (!f) {
return NULL;
}