firmware-utils: mkdapimg: fix compiler warnings/errors
authorPetr Štetiar <ynezz@true.cz>
Tue, 23 Jul 2019 21:04:08 +0000 (23:04 +0200)
committerPetr Štetiar <ynezz@true.cz>
Tue, 23 Jul 2019 21:04:08 +0000 (23:04 +0200)
mkdapimg.c:162:48: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
mkdapimg.c:206:48: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
mkdapimg.c:209:49: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
mkdapimg.c:211:51: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
mkdapimg.c:162:7: error: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Werror=unused-result]
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: error: ‘__builtin___strncpy_chk’ output may be truncated copying between 0 and 20 bytes from a string of length 30 [-Werror=stringop-truncation]
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ output may be truncated copying 20 bytes from a string of length 20 [-Werror=stringop-truncation]
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ output may be truncated copying 30 bytes from a string of length 30 [-Werror=stringop-truncation]
mkdapimg.c:216:7: error: ‘ofile’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
mkdapimg.c:225:2: error: ‘ifile’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

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

index 640f42d7c6c91a8bfc423a1a1c0941c87f96548d..bb073a83c7ca597c7bdad31313d3d2e3d6f66242 100644 (file)
@@ -68,7 +68,7 @@ main(int ac, char *av[])
        int fixmode = 0;
        int have_regionversion = 0;
 
-       FILE *ifile, *ofile;
+       FILE *ifile = NULL, *ofile = NULL;
        int c;
        uint32_t cksum;
        uint32_t bcnt;
@@ -155,11 +155,11 @@ main(int ac, char *av[])
                        fprintf(stderr, "%s: auto model name failed, string %s too long\n", progname, signature);
                        exit(1);
                }
-               strncpy(model, signature, p - signature);
+               memcpy(model, signature, p - signature);
        }
 
        if (patchmode) {
-               if (fread(&imghdr, sizeof(imghdr), 1, ifile) < 0)
+               if (fread(&imghdr, sizeof(imghdr), 1, ifile) != 1)
                        perrexit(2, "fread on input");
        }
 
@@ -200,15 +200,15 @@ main(int ac, char *av[])
                }
        }
 
-       strncpy(imghdr.model, model, MAX_MODEL_NAME_LEN);
-       strncpy(imghdr.sig, signature, MAX_SIG_LEN);
+       memcpy(imghdr.model, model, MAX_MODEL_NAME_LEN);
+       memcpy(imghdr.sig, signature, MAX_SIG_LEN);
 
-       if (fwrite(&imghdr, sizeof(imghdr), 1, ofile) < 0)
+       if (fwrite(&imghdr, sizeof(imghdr), 1, ofile) != 1)
                perrexit(2, "fwrite header on output");
        if (have_regionversion) {
-               if (fwrite(&region, MAX_REGION_LEN, 1, ofile) < 0)
+               if (fwrite(&region, MAX_REGION_LEN, 1, ofile) != 1)
                        perrexit(2, "fwrite header on output");
-               if (fwrite(&version, MAX_VERSION_LEN, 1, ofile) < 0)
+               if (fwrite(&version, MAX_VERSION_LEN, 1, ofile) != 1)
                        perrexit(2, "fwrite header on output");
        }