summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorIIMarckus <iimarckus@gmail.com>2017-06-29 22:45:30 -0600
committerIIMarckus <iimarckus@gmail.com>2017-06-29 22:45:30 -0600
commit80888726b9e5d8d62a8b1e76615bb11a1c9ca191 (patch)
tree30ca3db489f822926a80684d135d48af0585cdfb /tools
parent2ebbe91fe8fe87587e688bae49732d82a2f1f8b5 (diff)
Check some errors (not enough).
malloc can always fail. Check to avoid null dereference. malloc(0) is well defined but leads to an eventual crash on some systems. Check it too.
Diffstat (limited to 'tools')
-rw-r--r--tools/palette.c8
-rw-r--r--tools/pokemon_animation.c8
-rw-r--r--tools/pokemon_animation_graphics.c8
3 files changed, 24 insertions, 0 deletions
diff --git a/tools/palette.c b/tools/palette.c
index ebb8e4fbf..397c62651 100644
--- a/tools/palette.c
+++ b/tools/palette.c
@@ -50,9 +50,17 @@ void print_palette(char* palette_filename) {
fseek(f, 0, SEEK_END);
size = ftell(f);
+ if (!size) {
+ fprintf(stderr, "empty file %s\n", palette_filename);
+ exit(1);
+ }
rewind(f);
bytes = malloc(size);
+ if (!bytes) {
+ fprintf(stderr, "malloc failure\n");
+ exit(1);
+ }
fseek(f, 0, SEEK_SET);
fread(bytes, 1, size, f);
diff --git a/tools/pokemon_animation.c b/tools/pokemon_animation.c
index 5eadd6104..315a1729f 100644
--- a/tools/pokemon_animation.c
+++ b/tools/pokemon_animation.c
@@ -54,9 +54,17 @@ void make_frames(struct Frames* frames, struct Bitmasks* bitmasks, char* tilemap
fseek(f, 0, SEEK_END);
size = ftell(f);
+ if (!size) {
+ fprintf(stderr, "empty file %s\n", tilemap_filename);
+ exit(1);
+ }
rewind(f);
tilemap = malloc(size);
+ if (!tilemap) {
+ fprintf(stderr, "malloc failure\n");
+ exit(1);
+ }
fread(tilemap, 1, size, f);
fclose(f);
diff --git a/tools/pokemon_animation_graphics.c b/tools/pokemon_animation_graphics.c
index f38850fb0..ae96d7f17 100644
--- a/tools/pokemon_animation_graphics.c
+++ b/tools/pokemon_animation_graphics.c
@@ -90,8 +90,16 @@ void create_tilemap(struct Tilemap* tilemap, struct Graphic* graphic, char* grap
}
fseek(f, 0, SEEK_END);
graphics_size = ftell(f);
+ if (!graphics_size) {
+ fprintf(stderr, "empty file %s\n", graphics_filename);
+ exit(1);
+ }
rewind(f);
graphics = malloc(graphics_size);
+ if (!graphics) {
+ fprintf(stderr, "malloc failure\n");
+ exit(1);
+ }
fread(graphics, 1, graphics_size, f);
fclose(f);