From f4f723b99eb83f9a4cf2602020eb861fb6dbac43 Mon Sep 17 00:00:00 2001 From: Pavel Kalian Date: Sat, 19 Mar 2016 18:41:15 -0300 Subject: [PATCH] Use the return of fscanf --- ppm2bsb.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/ppm2bsb.c b/ppm2bsb.c index 2b0568a..42c8978 100644 --- a/ppm2bsb.c +++ b/ppm2bsb.c @@ -87,9 +87,25 @@ extern int main (int argc, char *argv[]) perror(argv[2]); exit(1); } - fscanf(ppm, "P%d\n", &magic); - fscanf(ppm, "%d %d\n", &image.width, &image.height); - fscanf(ppm, "%d\n", &max_sample); + int res = fscanf(ppm, "P%d\n", &magic); + if (res == EOF ) + { + perror(argv[2]); + exit(1); + } + res = fscanf(ppm, "%d %d\n", &image.width, &image.height); + if (res == EOF ) + { + perror(argv[2]); + exit(1); + } + res = fscanf(ppm, "%d\n", &max_sample); + if (res == EOF ) + { + perror(argv[2]); + exit(1); + } + start_of_raster = ftell(ppm); /* Count unique colors in the PPM file */