firmware-utils: wrt400n: fix compiler warnings/errors
authorPetr Štetiar <ynezz@true.cz>
Sat, 20 Jul 2019 12:03:10 +0000 (14:03 +0200)
committerPetr Štetiar <ynezz@true.cz>
Tue, 23 Jul 2019 20:07:23 +0000 (22:07 +0200)
wrt400n.c:97:16: error: comparison of integer expressions of different signedness: ‘int’ and ‘uint32_t’ {aka ‘unsigned int’} [-Werror=sign-compare]
wrt400n.c:209:16: error: comparison of integer expressions of different signedness: ‘uint32_t’ {aka ‘unsigned int’} and ‘int’ [-Werror=sign-compare]
wrt400n.c:234:16: error: comparison of integer expressions of different signedness: ‘uint32_t’ {aka ‘unsigned int’} and ‘int’ [-Werror=sign-compare]
wrt400n.c:312:2: error: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Werror=unused-result]

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

index 1cf1debc89341d9ffbc7dae94eb5af721a1c6376..b1d84c89765f2d43920db182c9a7611145ffd5e7 100644 (file)
@@ -7,6 +7,7 @@
  *
  *     Author: Sandeep Mistry
  */
+#include <errno.h>
 #include <arpa/inet.h>
 #include <fcntl.h>
 #include <stdio.h>
@@ -90,7 +91,7 @@ static uint32_t crctab[257] =
 
 static uint32_t crc32(uint8_t* buf, uint32_t len)
 {
-       register int i;
+       register unsigned int i;
        uint32_t sum;
        register uint32_t s0;
        s0 = ~0;
@@ -166,8 +167,8 @@ int main(int argc, char *argv[])
        char*           outputfilename  = NULL;
 
        // file sizes
-       uint32_t        kernelsize              = 0;
-       uint32_t        rootfssize              = 0;
+       ssize_t         kernelsize              = 0;
+       ssize_t         rootfssize              = 0;
        uint32_t        totalsize               = 0;
 
        // header flags
@@ -216,7 +217,7 @@ int main(int argc, char *argv[])
        kernelchecksum = cyg_crc32_accumulate(0, kernelbuf, sizeof(kernelbuf));
 
        // print out stats
-       printf("%s: size %d (0x%x), crc32 = 0x%x\n", kernelfilename, kernelsize, kernelsize, kernelchecksum);
+       printf("%s: size %ld (0x%lx), crc32 = 0x%x\n", kernelfilename, kernelsize, kernelsize, kernelchecksum);
 
 
        // open the root fs ..
@@ -241,7 +242,7 @@ int main(int argc, char *argv[])
        rootfschecksum = cyg_crc32_accumulate(0, rootfsbuf, sizeof(rootfsbuf));
 
        // print out stats
-       printf("%s: size %d (0x%x), crc32 = 0x%x\n", rootfsfilename, rootfssize, rootfssize, rootfschecksum);
+       printf("%s: size %ld (0x%lx), crc32 = 0x%x\n", rootfsfilename, rootfssize, rootfssize, rootfschecksum);
 
 
        // now for the header ...
@@ -307,9 +308,14 @@ int main(int argc, char *argv[])
        if(outfd == -1)
        {
                printf("ERROR: opening '%s' for write\n", outputfilename);
+               return -1;
        }
 
-       write(outfd, buf, totalsize);
+       ssize_t r = write(outfd, buf, totalsize);
+       if (r < 0) {
+               printf("ERROR: write '%s' error: %s (%d)\n", outputfilename, strerror(errno), errno);
+               return -1;
+       }
 
 done:
        // close open fd's