summaryrefslogtreecommitdiff
path: root/tools/pokemon_animation.c
diff options
context:
space:
mode:
authoryenatch <yenatch@gmail.com>2017-12-28 01:31:00 -0500
committerGitHub <noreply@github.com>2017-12-28 01:31:00 -0500
commite2b378f5e32ea1416fbc9ac5e96d23be244e4a6b (patch)
tree70fd1d4709150af457258763be04960931acd95b /tools/pokemon_animation.c
parentda28d1a84b0499bead314e17ae2ff0d13eb03196 (diff)
parent9af2aee640b555f9f52503233bc06d299b99974d (diff)
Merge pull request #442 from yenatch/fix-fread
fix fread warnings
Diffstat (limited to 'tools/pokemon_animation.c')
-rw-r--r--tools/pokemon_animation.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/tools/pokemon_animation.c b/tools/pokemon_animation.c
index 315a1729f..6e330a975 100644
--- a/tools/pokemon_animation.c
+++ b/tools/pokemon_animation.c
@@ -38,7 +38,7 @@ void make_frames(struct Frames* frames, struct Bitmasks* bitmasks, char* tilemap
uint8_t* tilemap;
uint8_t* this_frame;
FILE* f;
- long size;
+ size_t size;
int width;
int height;
uint8_t byte;
@@ -48,7 +48,7 @@ void make_frames(struct Frames* frames, struct Bitmasks* bitmasks, char* tilemap
f = fopen(tilemap_filename, "rb");
if (f == NULL) {
- fprintf(stderr, "could not open file %s", tilemap_filename);
+ fprintf(stderr, "could not open file %s\n", tilemap_filename);
exit(1);
}
@@ -65,15 +65,21 @@ void make_frames(struct Frames* frames, struct Bitmasks* bitmasks, char* tilemap
fprintf(stderr, "malloc failure\n");
exit(1);
}
- fread(tilemap, 1, size, f);
+ if (size != fread(tilemap, 1, size, f)) {
+ fprintf(stderr, "failed to read file %s\n", tilemap_filename);
+ exit(1);
+ }
fclose(f);
f = fopen(dimensions_filename, "rb");
if (f == NULL) {
- fprintf(stderr, "could not open file %s", dimensions_filename);
+ fprintf(stderr, "could not open file %s\n", dimensions_filename);
+ exit(1);
+ }
+ if (1 != fread(&byte, 1, 1, f)) {
+ fprintf(stderr, "failed to read file %s\n", dimensions_filename);
exit(1);
}
- fread(&byte, 1, 1, f);
fclose(f);
width = byte & 0xf;
@@ -137,7 +143,7 @@ void make_frames(struct Frames* frames, struct Bitmasks* bitmasks, char* tilemap
//}
//free(frames->frames);
- //fprintf(stderr, "num bitmasks: %d", bitmasks->num_bitmasks);
+ //fprintf(stderr, "num bitmasks: %d\n", bitmasks->num_bitmasks);
//for (i = 0; i < bitmasks->num_bitmasks; i++) {
// free(bitmasks->bitmasks[i].data);
// fprintf(stderr, "freed bitmask %d\n", i);
@@ -263,7 +269,7 @@ int main(int argc, char* argv[]) {
//ext = strrchr(argv[3], '.');
//if (!ext || ext == argv[3]) {
- // fprintf(stderr, "need a file extension to determine what to write to %s", argv[3]);
+ // fprintf(stderr, "need a file extension to determine what to write to %s\n", argv[3]);
//}
make_frames(&frames, &bitmasks, tilemap_filename, dimensions_filename);