SameBoy | Accurate GB/GBC emulator |
| download: https://git.y1.nz/archives/sameboy.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit a2a19ae31f982f0787391abb6bb41d95dda1bda5 parent 00f08bf3441019249df32b85701eada31a5f2ed4 Author: Lior Halphon <2345928+LIJI32@users.noreply.github.com> Date: Fri, 14 Nov 2025 20:37:54 +0200 Merge pull request #730 from AZero13/xcode Free expression if getline fails Diffstat:
| M | Core/cheats.c | 19 | ++++++++++++++----- |
| M | Core/gb.c | 1 | + |
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/Core/cheats.c b/Core/cheats.c @@ -289,16 +289,20 @@ int GB_load_cheats(GB_gameboy_t *gb, const char *path, bool replace_existing) uint32_t magic = 0; uint32_t struct_size = 0; - fread(&magic, sizeof(magic), 1, f); - fread(&struct_size, sizeof(struct_size), 1, f); + if (fread(&magic, sizeof(magic), 1, f) != 1) { + goto error; + } + if (fread(&struct_size, sizeof(struct_size), 1, f) != 1) { + goto error; + } if (magic != LE32(CHEAT_MAGIC) && magic != BE32(CHEAT_MAGIC)) { GB_log(gb, "The file is not a SameBoy cheat database"); - return -1; + goto error; } if (struct_size != sizeof(GB_cheat_t)) { GB_log(gb, "This cheat database is not compatible with this version of SameBoy"); - return -1; + goto error; } // Remove all cheats first @@ -307,7 +311,7 @@ int GB_load_cheats(GB_gameboy_t *gb, const char *path, bool replace_existing) } GB_cheat_t cheat; - while (fread(&cheat, sizeof(cheat), 1, f)) { + while (fread(&cheat, sizeof(cheat), 1, f) == 1) { if (magic != CHEAT_MAGIC) { cheat.address = __builtin_bswap16(cheat.address); cheat.bank = __builtin_bswap16(cheat.bank); @@ -316,7 +320,12 @@ int GB_load_cheats(GB_gameboy_t *gb, const char *path, bool replace_existing) GB_add_cheat(gb, cheat.description, cheat.address, cheat.bank, cheat.value, cheat.old_value, cheat.use_old_value, cheat.enabled); } + fclose(f); return 0; + +error: + fclose(f); + return -1; } int GB_save_cheats(GB_gameboy_t *gb, const char *path) diff --git a/Core/gb.c b/Core/gb.c @@ -58,6 +58,7 @@ static char *default_input_callback(GB_gameboy_t *gb) if (getline(&expression, &size, stdin) == -1) { /* The user doesn't have STDIN or used ^D. We make sure the program keeps running. */ + free(expression); GB_set_async_input_callback(gb, NULL); /* Disable async input */ return strdup("c"); }
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.