From 839f0c0c674befa8906fce0cb7ff6d2d3d034bc3 Mon Sep 17 00:00:00 2001 From: Rangi Date: Fri, 12 Jun 2026 11:57:21 -0400 Subject: [PATCH] Fix some issues with C tools, and build them with -std=c17 --- tools/Makefile | 2 +- tools/gfx.c | 3 +++ tools/make_patch.c | 5 +++-- tools/pokemon_animation.c | 12 +++++++++++- tools/stadium.c | 1 + 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/tools/Makefile b/tools/Makefile index 463b80b2b..a4cb44ece 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -1,7 +1,7 @@ .PHONY: all clean CC := gcc -CFLAGS := -O3 -std=c11 -Wall -Wextra -pedantic +CFLAGS := -O3 -std=c17 -Wall -Wextra -pedantic tools := \ gbcpal \ diff --git a/tools/gfx.c b/tools/gfx.c index c8f0b03f4..496cbabcf 100644 --- a/tools/gfx.c +++ b/tools/gfx.c @@ -67,6 +67,9 @@ void parse_args(int argc, char *argv[]) { break; case 'd': options.depth = strtoul(optarg, NULL, 0); + if (options.depth != 1 && options.depth != 2) { + error_exit("bit depth must be 1 or 2, not %d\n", options.depth); + } break; case 'p': options.png_file = optarg; diff --git a/tools/make_patch.c b/tools/make_patch.c index e4e15d7fd..c117f2c60 100644 --- a/tools/make_patch.c +++ b/tools/make_patch.c @@ -228,7 +228,8 @@ void interpret_command(char *command, const struct Symbol *current_hook, const s } // Get the arguments - char *argv[argc]; // VLA + char *argv[argc + 1]; // VLA (cannot be zero-length) + argv[argc] = NULL; char *arg = command; for (int i = 0; i < argc; i++) { while (*arg && !isspace((unsigned)*arg)) { @@ -515,7 +516,7 @@ int main(int argc, char *argv[]) { FILE *new_rom = xfopen(argv[1], 'r'); FILE *orig_rom = xfopen(argv[2], 'r'); if (new_rom == stdin || orig_rom == stdin) { - error_exit("Error: Cannot read ROM file from stdin (not rewindable)"); + error_exit("Error: Cannot read ROM file from stdin (not rewindable)\n"); } struct Buffer *patches = process_template(argv[3], argv[4], new_rom, orig_rom, symbols, ignore_addr, ignore_size); diff --git a/tools/pokemon_animation.c b/tools/pokemon_animation.c index 2c8ad6446..07972c85f 100644 --- a/tools/pokemon_animation.c +++ b/tools/pokemon_animation.c @@ -118,10 +118,12 @@ void make_frames(const uint8_t *tilemap, long tilemap_size, int width, struct Fr bitmasks->num_bitmasks++; } else { free(bitmask->data); - free(bitmask); } frames->frames[i] = *frame; this_frame += num_tiles_per_frame; + + free(frame); + free(bitmask); } } @@ -191,5 +193,13 @@ int main(int argc, char *argv[]) { } free(tilemap); + for (int i = 0; i < frames.num_frames; i++) { + free(frames.frames[i].data); + } + free(frames.frames); + for (int i = 0; i < bitmasks.num_bitmasks; i++) { + free(bitmasks.bitmasks[i].data); + } + free(bitmasks.bitmasks); return 0; } diff --git a/tools/stadium.c b/tools/stadium.c index 473e27776..355fa2092 100644 --- a/tools/stadium.c +++ b/tools/stadium.c @@ -199,5 +199,6 @@ int main(int argc, char *argv[]) { calculate_checksums(file, european); } write_u8(filename, file, filesize); + free(file); return 0; }