Skip to content

Commit 06ec23c

Browse files
authored
Fix some issues with C tools, and build them with -std=c17 (#1259)
1 parent fb7b0d7 commit 06ec23c

5 files changed

Lines changed: 19 additions & 4 deletions

File tree

tools/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.PHONY: all clean
22

33
CC := gcc
4-
CFLAGS := -O3 -std=c11 -Wall -Wextra -pedantic
4+
CFLAGS := -O3 -std=c17 -Wall -Wextra -pedantic
55

66
tools := \
77
gbcpal \

tools/gfx.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ void parse_args(int argc, char *argv[]) {
6767
break;
6868
case 'd':
6969
options.depth = strtoul(optarg, NULL, 0);
70+
if (options.depth != 1 && options.depth != 2) {
71+
error_exit("bit depth must be 1 or 2, not %d\n", options.depth);
72+
}
7073
break;
7174
case 'p':
7275
options.png_file = optarg;

tools/make_patch.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ void interpret_command(char *command, const struct Symbol *current_hook, const s
228228
}
229229

230230
// Get the arguments
231-
char *argv[argc]; // VLA
231+
char *argv[argc + 1]; // VLA (cannot be zero-length)
232+
argv[argc] = NULL;
232233
char *arg = command;
233234
for (int i = 0; i < argc; i++) {
234235
while (*arg && !isspace((unsigned)*arg)) {
@@ -515,7 +516,7 @@ int main(int argc, char *argv[]) {
515516
FILE *new_rom = xfopen(argv[1], 'r');
516517
FILE *orig_rom = xfopen(argv[2], 'r');
517518
if (new_rom == stdin || orig_rom == stdin) {
518-
error_exit("Error: Cannot read ROM file from stdin (not rewindable)");
519+
error_exit("Error: Cannot read ROM file from stdin (not rewindable)\n");
519520
}
520521
struct Buffer *patches = process_template(argv[3], argv[4], new_rom, orig_rom, symbols, ignore_addr, ignore_size);
521522

tools/pokemon_animation.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,12 @@ void make_frames(const uint8_t *tilemap, long tilemap_size, int width, struct Fr
118118
bitmasks->num_bitmasks++;
119119
} else {
120120
free(bitmask->data);
121-
free(bitmask);
122121
}
123122
frames->frames[i] = *frame;
124123
this_frame += num_tiles_per_frame;
124+
125+
free(frame);
126+
free(bitmask);
125127
}
126128
}
127129

@@ -191,5 +193,13 @@ int main(int argc, char *argv[]) {
191193
}
192194

193195
free(tilemap);
196+
for (int i = 0; i < frames.num_frames; i++) {
197+
free(frames.frames[i].data);
198+
}
199+
free(frames.frames);
200+
for (int i = 0; i < bitmasks.num_bitmasks; i++) {
201+
free(bitmasks.bitmasks[i].data);
202+
}
203+
free(bitmasks.bitmasks);
194204
return 0;
195205
}

tools/stadium.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,5 +199,6 @@ int main(int argc, char *argv[]) {
199199
calculate_checksums(file, european);
200200
}
201201
write_u8(filename, file, filesize);
202+
free(file);
202203
return 0;
203204
}

0 commit comments

Comments
 (0)