From 0f10ccc487d6ce2498b7ed30a44ce51f360b7b01 Mon Sep 17 00:00:00 2001 From: Maschell Date: Mon, 14 Feb 2022 19:30:59 +0100 Subject: [PATCH] Read the meta.ini into memory on the heap --- src/main.cpp | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ae88c19..9c851ea 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -211,21 +212,26 @@ void readCustomTitlesFromSD() { uint32_t file_handle = 0; if (RL_FileOpen("romfscheck:/meta/meta.ini", &file_handle) == 0) { // this buffer should be big enough for our .ini - char ini_buffer[0x1000]; - memset(ini_buffer, 0, sizeof(ini_buffer)); - uint32_t offset = 0; - uint32_t toRead = sizeof(ini_buffer); - do { - int res = RL_FileRead(file_handle, reinterpret_cast(&ini_buffer[offset]), toRead); - if (res <= 0) { - break; - } - offset += res; - toRead -= res; - } while (offset < sizeof(ini_buffer)); + char *ini_buffer = (char *) memalign(0x40, 0x1000); + if (ini_buffer) { + memset(ini_buffer, 0, 0x1000); + uint32_t offset = 0; + uint32_t toRead = 0x1000; + do { + int res = RL_FileRead(file_handle, reinterpret_cast(&ini_buffer[offset]), toRead); + if (res <= 0) { + break; + } + offset += res; + toRead -= res; + } while (offset < sizeof(ini_buffer)); - if (ini_parse_string(ini_buffer, handler, &gFileInfos[j]) < 0) { - DEBUG_FUNCTION_LINE("Failed to parse ini"); + if (ini_parse_string(ini_buffer, handler, &gFileInfos[j]) < 0) { + DEBUG_FUNCTION_LINE("Failed to parse ini"); + } + free(ini_buffer); + } else { + DEBUG_FUNCTION_LINE("Failed to alloc memory"); } RL_FileClose(file_handle);