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:
@@ -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);
|
||||
|
Reference in New Issue
Block a user