[U-Boot] [PATCH] kwbimage: Correct a long-standing warning

tools/kwbimage.c:803:8: warning: 'headersz' may be used uninitialized in this function [-Wmaybe-uninitialized]
This problem was discussed twice previously, but neither solution has been applied to mainline. This is another attempt at a possible solution before the release goes out and we are stuck with it.
https://patchwork.ozlabs.org/patch/412968/ https://patchwork.ozlabs.org/patch/417410/
Signed-off-by: Simon Glass sjg@chromium.org ---
tools/kwbimage.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index c50f2e2..937b208 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -302,6 +302,7 @@ static void *image_create_v0(size_t *imagesz, struct image_tool_params *params, * Calculate the size of the header and the size of the * payload */ + *imagesz = 0; headersz = sizeof(struct main_hdr_v0);
if (image_count_options(IMAGE_CFG_DATA) > 0) { @@ -441,6 +442,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, * Calculate the size of the header and the size of the * payload */ + *imagesz = 0; headersz = image_headersz_v1(params, &hasext); if (headersz == 0) return NULL; @@ -737,7 +739,7 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, if (!fcfg) { fprintf(stderr, "Could not open input file %s\n", params->imagename); - exit(EXIT_FAILURE); + goto err; }
image_cfg = malloc(IMAGE_CFG_ELEMENT_MAX * @@ -745,7 +747,7 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, if (!image_cfg) { fprintf(stderr, "Cannot allocate memory\n"); fclose(fcfg); - exit(EXIT_FAILURE); + goto err; }
memset(image_cfg, 0, @@ -756,7 +758,7 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, fclose(fcfg); if (ret) { free(image_cfg); - exit(EXIT_FAILURE); + goto err; }
version = image_get_version(); @@ -777,13 +779,13 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, default: fprintf(stderr, "Unsupported version %d\n", version); free(image_cfg); - exit(EXIT_FAILURE); + goto err; }
if (!image) { fprintf(stderr, "Could not create image\n"); free(image_cfg); - exit(EXIT_FAILURE); + goto err; }
free(image_cfg); @@ -794,7 +796,7 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, if (size != sizeof(uint32_t)) { fprintf(stderr, "Error:%s - Checksum write %d bytes %s\n", params->cmdname, size, params->imagefile); - exit(EXIT_FAILURE); + goto err; }
sbuf->st_size += sizeof(uint32_t); @@ -803,6 +805,13 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, memcpy(ptr, image, headersz);
free(image); + +err: + /* + * TODO: Adjust the struct image_type_params set_header() method to + * return an error instead of calling exit() here. + */ + exit(EXIT_FAILURE); }
static void kwbimage_print_header(const void *ptr)
participants (1)
-
Simon Glass