Skip to contentSkip to conversation

tools/kwbimage: Fix compilation warning

PATCH New Stefan Roese 4 participants 4 messages Oct 28, 2014 – Nov 13, 2014

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tools/kwbimage: Fix compilation warning

This patch fixes a compilation warning of kwbimage.c:

tools/kwbimage.c: In function ?kwbimage_set_header?:
tools/kwbimage.c:784:8: warning: ?headersz? may be used uninitialized in this function [-Wmaybe-uninitialized]

  memcpy(ptr, image, headersz);
        ^

Instead of using multiple if statements, use a switch statement with a default entry. And return with error if an unsupported version is configured in the cfg file.

---
v2:
- Change error message so that it really makes sense (unsupported version instead of no version)
- Change this also in the commit text
- Small change (s/is/if)

 tools/kwbimage.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)
tools/kwbimage.c +17 -6
index 1120e9b..0179c74 100644
@@ -752,14 +752,25 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd,
 	}
 
 	version = image_get_version();
-	/* Fallback to version 0 is no version is provided in the cfg file */
-	if (version == -1)
-		version = 0;
-
-	if (version == 0)
+	switch (version) {
+		/*
+		 * Fallback to version 0 if no version is provided in the
+		 * cfg file
+		 */
+	case -1:
+	case 0:
 		image = image_create_v0(&headersz, params, sbuf->st_size);
-	else if (version == 1)
+		break;
+
+	case 1:
 		image = image_create_v1(&headersz, params, sbuf->st_size);
+		break;
+
+	default:
+		fprintf(stderr, "Unsupported version %d\n", version);
+		free(image_cfg);
+		exit(EXIT_FAILURE);
+	}
 
 	if (!image) {
 		fprintf(stderr, "Could not create image\n");
Signature · 1 line
2.1.2
#1 lore raw

PATCH v2 1/1 tools/kwbimage: Fix compilation warning

Dear Stefan Roese,

Quoted 10 lines · In message <[email protected]> you wrote:

This patch fixes a compilation warning of kwbimage.c:

tools/kwbimage.c: In function ?kwbimage_set_header?:
tools/kwbimage.c:784:8: warning: ?headersz? may be used uninitialized in this function [-Wmaybe-uninitialized]

  memcpy(ptr, image, headersz);
        ^

Instead of using multiple if statements, use a switch statement with a default entry. And return with error if an unsupported version is configured in the cfg file.

Quoted 7 lines

---
v2:
- Change error message so that it really makes sense (unsupported version instead of no version)
- Change this also in the commit text
- Small change (s/is/if)

Thanks!

Best regards,

Wolfgang Denk

Signature · 7 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Es ist offensichtlich, dass das menschliche Gehirn wie  ein  Computer
funktioniert.  Da  es  keine  dummen Computer gibt, gibt es also auch
keine dummen Menschen. Nur ein paar Leute, die unter DOS laufen.
                                                       -- <unbekannt>
#2 lore raw

PATCH v2 1/1 tools/kwbimage: Fix compilation warning

Quoted 21 lines · Wolfgang Denk

Dear Stefan Roese,

Quoted 10 lines · In message <[email protected]> you wrote:

This patch fixes a compilation warning of kwbimage.c:

tools/kwbimage.c: In function ?kwbimage_set_header?:
tools/kwbimage.c:784:8: warning: ?headersz? may be used uninitialized in this function [-Wmaybe-uninitialized]

  memcpy(ptr, image, headersz);
        ^

Instead of using multiple if statements, use a switch statement with a default entry. And return with error if an unsupported version is configured in the cfg file.

Quoted 7 lines

---
v2:
- Change error message so that it really makes sense (unsupported version instead of no version)
- Change this also in the commit text
- Small change (s/is/if)

Quoted 2 lines

I failed to see how the warning message got fixed. I still see this warning when compiling.

York

#3 lore raw

PATCH v2 1/1 tools/kwbimage: Fix compilation warning

In reply to Stefan Roese
Quoted 18 lines · On Tue, 28 Oct 2014 11:32:24 +0100 Stefan Roese <[email protected]> wrote:

This patch fixes a compilation warning of kwbimage.c:

tools/kwbimage.c: In function ?kwbimage_set_header?:
tools/kwbimage.c:784:8: warning: ?headersz? may be used uninitialized in this function [-Wmaybe-uninitialized]

  memcpy(ptr, image, headersz);
        ^

Instead of using multiple if statements, use a switch statement with a default entry. And return with error if an unsupported version is configured in the cfg file.

---
v2:
- Change error message so that it really makes sense (unsupported version instead of no version)
- Change this also in the commit text
- Small change (s/is/if)

Quoted 2 lines
 tools/kwbimage.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

Applied to u-boot-staging. Thanks!

Anatolij