firmware-utils: seama: fix compiler warnings/errors
authorPetr Štetiar <ynezz@true.cz>
Sat, 20 Jul 2019 12:33:13 +0000 (14:33 +0200)
committerPetr Štetiar <ynezz@true.cz>
Tue, 23 Jul 2019 20:07:23 +0000 (22:07 +0200)
seama.c:334:16: error: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Werror=sign-compare]
seama.c:352:14: error: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Werror=sign-compare]
seama.c:374:13: error: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Werror=sign-compare]
seama.c:411:16: error: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Werror=sign-compare]
seama.c:438:16: error: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Werror=sign-compare]
seama.c:453:4: error: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Werror=unused-result]
seama.c:469:4: error: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Werror=unused-result]
seama.c:473:5: error: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Werror=unused-result]

Signed-off-by: Petr Štetiar <ynezz@true.cz>
tools/firmware-utils/src/seama.c

index 05aee8e76aacd8824bdfa300f5bc2e6092d05c5b..bc27d3f1362c5e9dbf94868cdef0cdc10b705650 100644 (file)
@@ -65,9 +65,9 @@ static char * o_dump = NULL;          /* Seama file to dump. */
 static char *  o_seal = NULL;          /* Seal the input images when file name exist. */
 static char *  o_extract = NULL;       /* Extract the seama file. */
 static char *  o_images[MAX_IMAGE];/* The image files to pack or seal */
-static int             o_isize = 0;            /* number of images */
+static size_t  o_isize = 0;            /* number of images */
 static char *  o_meta[MAX_META];       /* meta data array */
-static int             o_msize = 0;            /* size of meta array */
+static size_t  o_msize = 0;            /* size of meta array */
 
 static void verbose(const char * format, ...)
 {
@@ -450,7 +450,11 @@ static void extract_file(const char * output)
                while (!feof(ifh) && !ferror(ifh))
                {
                        /* read header */
-                       fread(&shdr, sizeof(shdr), 1, ifh);
+                       if (fread(&shdr, sizeof(shdr), 1, ifh) != 1) {
+                               printf("SEAMA: error reading header\n");
+                               break;
+                       }
+
                        if (shdr.magic != htonl(SEAMA_MAGIC)) break;
                        /* Get the size */
                        isize = ntohl(shdr.size);
@@ -466,11 +470,19 @@ static void extract_file(const char * output)
                                continue;
                        }
                        /* read checksum */
-                       fread(buf, sizeof(char), 16, ifh);
+                       if (fread(buf, sizeof(char), 16, ifh) != 16) {
+                               printf("SEAMA: error reading checksum\n");
+                               break;
+                       }
+
                        if (msize > 0)
                        {
                                /* read META */
-                               fread(buf, sizeof(char), msize, ifh);
+                               if (fread(buf, sizeof(char), msize, ifh) != msize) {
+                                       printf("SEAMA: error reading meta\n");
+                                       break;
+                               }
+
                                if (match_meta((const char *)buf, msize))
                                {
                                        printf("SEAMA: found image @ '%s', image size: %zu\n", o_images[i], isize);