mirror of
https://gitlab.com/xCrystal/pokecrystal-board.git
synced 2024-11-16 11:27:33 -08:00
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.
This commit is contained in:
parent
2ebbe91fe8
commit
80888726b9
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user