Skip to content

Commit 6c03b29

Browse files
committed
firmware-utils: fix dgn3500sum compiler warnings
The sum variable need to be initialised, otherwise it will points to random stack memory and a bogus image checksum might be calculated. While at it, fix the segfault in case the product region code isn't specified and enable compiler warnings which had revealed all the code issues. Signed-off-by: Mathias Kresin <[email protected]>
1 parent 73a4568 commit 6c03b29

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

tools/firmware-utils/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ define Host/Compile
7373
$(call cc,mkdcs932, -Wall)
7474
$(call cc,mkheader_gemtek,-lz)
7575
$(call cc,mkrtn56uimg, -lz)
76-
$(call cc,dgn3500sum)
76+
$(call cc,dgn3500sum, -Wall)
7777
$(call cc,edimax_fw_header, -Wall)
7878
$(call cc,mkmerakifw sha1, -Wall)
7979
$(call cc,mkmerakifw-old, -Wall)

tools/firmware-utils/src/dgn3500sum.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ int main(int argc, char** argv)
103103
unsigned long start, i;
104104
char *endptr, *buffer, *p;
105105
int count; // size of file in bytes
106-
unsigned short sum, sum1;
106+
unsigned short sum = 0, sum1 = 0;
107107
char sumbuf[9];
108108

109109
if(argc < 3) {
@@ -117,7 +117,7 @@ int main(int argc, char** argv)
117117
printf("ERROR: File not writeable!\n");
118118
return 1;
119119
}
120-
if(argc = 4)
120+
if(argc == 4)
121121
{
122122
printf("%s: PID type: %s\n", argv[0], argv[3]);
123123
if(strcmp(argv[3], "DE")==0)
@@ -147,7 +147,6 @@ int main(int argc, char** argv)
147147

148148
start = strtol(argv[2], &endptr, 16);
149149
p = buffer+start;
150-
sum1 = 0;
151150
for(i = 0; i < count - start; i++)
152151
{
153152
sum1 += p[i];

0 commit comments

Comments
 (0)