[LEDE-DEV] [PATCH 2/2] firmware-utils: mkdapimg2: Fix a few issues discovered by clang
Rosen Penev
rosenp at gmail.com
Sun Apr 22 16:22:39 PDT 2018
I used clang -Weverything and fixed most of the warnings displayed.
Signed-off-by: Rosen Penev <rosenp at gmail.com>
---
tools/firmware-utils/src/mkdapimg2.c | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/tools/firmware-utils/src/mkdapimg2.c b/tools/firmware-utils/src/mkdapimg2.c
index 59c9f00..89febbc 100644
--- a/tools/firmware-utils/src/mkdapimg2.c
+++ b/tools/firmware-utils/src/mkdapimg2.c
@@ -58,7 +58,7 @@
#define MAX_FW_VER_LEN 16
#define MAX_REG_LEN 8
-struct img_hdr_struct {
+static struct img_hdr_struct {
uint32_t hdr_len;
uint32_t checksum;
uint32_t total_size;
@@ -68,17 +68,17 @@ struct img_hdr_struct {
char fw_reg[MAX_REG_LEN];
} imghdr ;
-char *progname;
+static char *progname;
-void
+static void
perrexit(int code, char *msg)
{
fprintf(stderr, "%s: %s: %s\n", progname, msg, strerror(errno));
exit(code);
}
-void
-usage()
+static void
+usage(void)
{
fprintf(stderr, "usage: %s -s signature [-v version] [-r region] [-k uImage part size] -i <input> -o <output>\n", progname);
exit(1);
@@ -92,7 +92,7 @@ main(int ac, char *av[])
char region[MAX_REG_LEN];
int kernel = 0;
- FILE *ifile, *ofile;
+ FILE *ifile = NULL, *ofile = NULL;
int c;
uint32_t cksum;
@@ -138,7 +138,7 @@ main(int ac, char *av[])
strncpy(region, optarg, MAX_REG_LEN);
break;
case 'k':
- kernel = strtoul(optarg, &ptr, 0);
+ kernel = strtol(optarg, &ptr, 0);
if(ptr[0] == 'k'){
kernel *= 1000;
}
@@ -156,10 +156,8 @@ main(int ac, char *av[])
}
}
- if (signature[0] == 0 || ifile == NULL || ofile == NULL) {
+ if (signature[0] == 0 || ifile == NULL || ofile == NULL)
usage();
- exit(1);
- }
for (bcnt = 0, cksum = 0 ; (c = fgetc(ifile)) != EOF ; bcnt++)
cksum += c & 0xff;
@@ -178,7 +176,7 @@ main(int ac, char *av[])
strncpy(imghdr.fw_ver, version, MAX_FW_VER_LEN);
strncpy(imghdr.fw_reg, region, MAX_REG_LEN);
- if (fwrite(&imghdr, sizeof(imghdr), 1, ofile) < 0)
+ if (fwrite(&imghdr, sizeof(imghdr), 1, ofile) != 1)
perrexit(2, "fwrite header on output");
while ((c = fgetc(ifile)) != EOF) {
--
2.7.4
More information about the Lede-dev
mailing list