From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefan Roese Date: Mon, 27 Oct 2014 14:09:38 +0100 Subject: [U-Boot] [PATCH] tools/kwbimage: Fix compilation warning In-Reply-To: <20141027125743.122C9380909@gemini.denx.de> References: <1414412953-25615-1-git-send-email-sr@denx.de> <20141027125743.122C9380909@gemini.denx.de> Message-ID: <544E4412.60603@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hi Wolfgang, On 27.10.2014 13:57, Wolfgang Denk wrote: >> 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. > > Thanks, but... > >> + 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); >> + 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); >> + } > > What exactly is the difference between return code -1 (no version is > provided and you fall back to using version 0), and the default case? > > To me these look the same? Perhaps the error message is a bit misleading. The "default:" case is for unsupported versions. E.g. if "VERSION 3" would have been provided in the cfg file. Should I rephrase the error message in the next patch version? To something like this: fprintf(stderr, "Unsupported VERSION %d\n", version); Thanks, Stefan