From: Lukasz Majewski <l.majewski@samsung.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] fix: tools: kwbimage.c: Initialize headersz to suppress warning
Date: Fri, 21 Nov 2014 10:20:26 +0100 [thread overview]
Message-ID: <20141121102026.75aad6e2@amdc2363> (raw)
In-Reply-To: <20141121093514.5166e9fd@free-electrons.com>
Hi Thomas,
> Dear Lukasz Majewski,
>
> Thanks for your patch.
>
> On Fri, 21 Nov 2014 09:22:43 +0100, Lukasz Majewski wrote:
> > When building with my toolchain (4.8.2):
> > CROSS_COMPILE=/home/lukma/work/ptxdist/toolchains/arm/OSELAS.Toolchain-2013.12.0/arm-v7a-linux-gnueabi/gcc-4.8.2-glibc-2.18-binutils-2.24-kernel-3.12-sanitized/bin/arm-v7a-linux-gnueabi-
>
> Well, your target toolchain doesn't have much to do about the issue.
> tools/kwbimage.c is built for the host.
Yes. Correct.
Host: gcc version 4.7.2 (Debian 4.7.2-5)
>
> > I see following WARNING:
> > tools/kwbimage.c: In function "kwbimage_set_header":
> > tools/kwbimage.c:803:8: warning: "headersz" may be used
> > uninitialized in this function [-Wmaybe-uninitialized] memcpy(ptr,
> > image, headersz); ^
> > This fix aims to suppress it.
> >
> > Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
> > ---
> > tools/kwbimage.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/kwbimage.c b/tools/kwbimage.c
> > index c50f2e2..2c302e5 100644
> > --- a/tools/kwbimage.c
> > +++ b/tools/kwbimage.c
> > @@ -728,7 +728,7 @@ static void kwbimage_set_header(void *ptr,
> > struct stat *sbuf, int ifd, FILE *fcfg;
> > void *image = NULL;
> > int version;
> > - size_t headersz;
> > + size_t headersz = 0;
> > uint32_t checksum;
> > int ret;
> > int size;
>
> Looking briefly again at the code, I believe the warning from gcc is
> probably bogus. Here is the code:
>
> size_t headersz;
> [...]
> version = image_get_version();
> 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); 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);
> }
> [...]
> /* Finally copy the header into the image area */
> memcpy(ptr, image, headersz);
>
> So the usage of 'headersz' is only done if we have gone through either
> the -1/0/1 cases. In the 'default' case, we exit the tool, so the
> memcpy() is never reached. Maybe gcc doesn't realize we're getting out
> of the function in the default case.
>
> But oh well, if it fixes a warning :-)
I didn't claim that there is a bug in the code :-).
I just get annoying when on my continuous integration script I see the
same warning for all cross compiled boards.
Anyway, I assume that you don't have any objections to this patch :-) .
>
> Best regards,
>
> Thomas
--
Best regards,
Lukasz Majewski
Samsung R&D Institute Poland (SRPOL) | Linux Platform Group
next prev parent reply other threads:[~2014-11-21 9:20 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-21 8:22 [U-Boot] [PATCH] fix: tools: kwbimage.c: Initialize headersz to suppress warning Lukasz Majewski
2014-11-21 8:35 ` Thomas Petazzoni
2014-11-21 9:20 ` Lukasz Majewski [this message]
2014-11-21 12:34 ` Jeroen Hofstee
2014-11-21 15:30 ` Albert ARIBAUD
2014-11-21 19:34 ` Jeroen Hofstee
2014-11-22 6:56 ` Lukasz Majewski
2014-11-22 12:17 ` Albert ARIBAUD
2014-11-23 17:38 ` Lukasz Majewski
2014-11-24 8:39 ` Lukasz Majewski
2014-11-24 18:00 ` Albert ARIBAUD
2014-12-08 11:40 ` Lukasz Majewski
2014-11-24 8:52 ` Guillaume Gardet
2014-11-21 9:54 ` Stefan Roese
2014-11-21 10:14 ` Heiko Schocher
2014-11-21 21:52 ` Albert ARIBAUD
2015-01-10 19:10 ` [U-Boot] " Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20141121102026.75aad6e2@amdc2363 \
--to=l.majewski@samsung.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox