public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] tools/kwbimage: Fix compilation warning
@ 2014-10-27 12:29 Stefan Roese
  2014-10-27 12:57 ` Wolfgang Denk
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Roese @ 2014-10-27 12:29 UTC (permalink / raw)
  To: u-boot

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 the VERSION field is
missing in the cfg file.

Signed-off-by: Stefan Roese <sr@denx.de>
---
 tools/kwbimage.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 1120e9b..91db5d7 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -752,14 +752,26 @@ 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 is 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, "File %s does not have the VERSION field\n",
+			params->imagename);
+		free(image_cfg);
+		exit(EXIT_FAILURE);
+	}
 
 	if (!image) {
 		fprintf(stderr, "Could not create image\n");
-- 
2.1.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-10-27 16:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-27 12:29 [U-Boot] [PATCH] tools/kwbimage: Fix compilation warning Stefan Roese
2014-10-27 12:57 ` Wolfgang Denk
2014-10-27 13:09   ` Stefan Roese
2014-10-27 13:34     ` Wolfgang Denk
2014-10-27 16:47       ` Stefan Roese

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox