[U-Boot] [PATCH] kwbimage.c: Fix compile warning when building on 32/64 bit systems

Commit 51003b89 [kwbimage.c: Fix compile warning when building on 64 bit systems] changed the printf format for "sizeof(uint32_t)" from "%d" to "%ld". This now generates the following warning on 32 bit build systems:
tools/kwbimage.c: In function ‘kwbimage_checksum32’: tools/kwbimage.c:135: warning: format ‘%ld’ expects type ‘long int’, but argument 4 has type ‘unsigned int’
The problem is that sizeof(uint32_t) has different types on 32 bit and 64 bit build systems. This patch now changes the format to "%d" again and casts sizeof() to uint32_t, fixing the problem on both build systems.
Signed-off-by: Stefan Roese sr@denx.de Cc: Wolfgang Denk wd@denx.de Cc: Prafulla Wadaskar prafulla@marvell.com --- tools/kwbimage.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index ee067cb..2c542da 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -131,8 +131,8 @@ static uint32_t kwbimage_checksum32 (uint32_t *start, uint32_t len, uint32_t csu return 0;
if (len % sizeof(uint32_t)) { - printf ("Error:%s[%d] - lenght is not in multiple of %ld\n", - __FUNCTION__, len, sizeof(uint32_t)); + printf ("Error:%s[%d] - lenght is not in multiple of %d\n", + __FUNCTION__, len, (uint32_t)sizeof(uint32_t)); return 0; }

Dear Stefan Roese,
In message 1253002223-16773-1-git-send-email-sr@denx.de you wrote:
Commit 51003b89 [kwbimage.c: Fix compile warning when building on 64 bit systems] changed the printf format for "sizeof(uint32_t)" from "%d" to "%ld". This now generates the following warning on 32 bit build systems:
tools/kwbimage.c: In function `kwbimage_checksum32´: tools/kwbimage.c:135: warning: format `%ld´ expects type `long int´, but argument 4 has type `unsigned int´
The problem is that sizeof(uint32_t) has different types on 32 bit and 64 bit build systems. This patch now changes the format to "%d" again and casts sizeof() to uint32_t, fixing the problem on both build systems.
Heh. Casts are evil.
Now that both of us stabbed at this and failed it's time to remember to use "%zu" (hm... now why does this remind me of dzu? ;-)
Will submit a patch ASAP.
Best regards,
Wolfgang Denk

On Tuesday 15 September 2009 04:10:23 Stefan Roese wrote:
Commit 51003b89 [kwbimage.c: Fix compile warning when building on 64 bit systems] changed the printf format for "sizeof(uint32_t)" from "%d" to "%ld". This now generates the following warning on 32 bit build systems:
tools/kwbimage.c: In function ‘kwbimage_checksum32’: tools/kwbimage.c:135: warning: format ‘%ld’ expects type ‘long int’, but argument 4 has type ‘unsigned int’
The problem is that sizeof(uint32_t) has different types on 32 bit and 64 bit build systems. This patch now changes the format to "%d" again and casts sizeof() to uint32_t, fixing the problem on both build systems.
if (len % sizeof(uint32_t)) {
printf ("Error:%s[%d] - lenght is not in multiple of %ld\n",
__FUNCTION__, len, sizeof(uint32_t));
printf ("Error:%s[%d] - lenght is not in multiple of %d\n",
__FUNCTION__, len, (uint32_t)sizeof(uint32_t));
why not do it right ? use PRIu32 from inttypes.h like POSIX intended. might as well fix the typo in the message ("length") while you're here, and use the standardized __func__ ... -mike

Dear Mike Frysinger,
In message 200909151213.38895.vapier@gentoo.org you wrote:
if (len % sizeof(uint32_t)) {
printf ("Error:%s[%d] - lenght is not in multiple of %ld\n",
__FUNCTION__, len, sizeof(uint32_t));
printf ("Error:%s[%d] - lenght is not in multiple of %d\n",
__FUNCTION__, len, (uint32_t)sizeof(uint32_t));
why not do it right ? use PRIu32 from inttypes.h like POSIX intended. might
I don't think that would fix it, as PRIu32 is just "u", but what we really need to be compatible with both 32 and 64 bit environments is "%zu".
as well fix the typo in the message ("length") while you're here, and use the
Ah, well spotted. Thanks.
standardized __func__ ...
Well, ok. Next time, maybe ;-)
Best regards,
Wolfgang Denk

On Tuesday 15 September 2009 15:36:54 Wolfgang Denk wrote:
Mike Frysinger wrote:
if (len % sizeof(uint32_t)) {
printf ("Error:%s[%d] - lenght is not in multiple of %ld\n",
__FUNCTION__, len, sizeof(uint32_t));
printf ("Error:%s[%d] - lenght is not in multiple of %d\n",
__FUNCTION__, len, (uint32_t)sizeof(uint32_t));
why not do it right ? use PRIu32 from inttypes.h like POSIX intended. might
I don't think that would fix it, as PRIu32 is just "u", but what we really need to be compatible with both 32 and 64 bit environments is "%zu".
i thought it was printing a u32. a sizeof() is size_t, so use %zu. -mike

Commit 51003b89 attempted to fix a build problem on 64 bit systems, but just turned it into a build problem on 32 bit systems (silly me).
Now do the Right Thing (TM) and use a "%zu" printf format.
Signed-off-by: Wolfgang Denk wd@denx.de --- tools/kwbimage.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index ee067cb..b555553 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -131,7 +131,7 @@ static uint32_t kwbimage_checksum32 (uint32_t *start, uint32_t len, uint32_t csu return 0;
if (len % sizeof(uint32_t)) { - printf ("Error:%s[%d] - lenght is not in multiple of %ld\n", + printf ("Error:%s[%d] - lenght is not in multiple of %zu\n", __FUNCTION__, len, sizeof(uint32_t)); return 0; }

Commit 51003b89 attempted to fix a build problem on 64 bit systems, but just turned it into a build problem on 32 bit systems (silly me).
Now do the Right Thing (TM) and use a "%zu" printf format.
Also fix spelling error.
Signed-off-by: Wolfgang Denk wd@denx.de --- v2: Also fix spelling error; cudos Mike Frysinger
tools/kwbimage.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index ee067cb..7b26920 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -131,7 +131,7 @@ static uint32_t kwbimage_checksum32 (uint32_t *start, uint32_t len, uint32_t csu return 0;
if (len % sizeof(uint32_t)) { - printf ("Error:%s[%d] - lenght is not in multiple of %ld\n", + printf ("Error:%s[%d] - length is not in multiple of %zu\n", __FUNCTION__, len, sizeof(uint32_t)); return 0; }

In message 1253043494-11436-1-git-send-email-wd@denx.de you wrote:
Commit 51003b89 attempted to fix a build problem on 64 bit systems, but just turned it into a build problem on 32 bit systems (silly me).
Now do the Right Thing (TM) and use a "%zu" printf format.
Also fix spelling error.
Signed-off-by: Wolfgang Denk wd@denx.de
v2: Also fix spelling error; cudos Mike Frysinger
tools/kwbimage.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
Applied.
Best regards,
Wolfgang Denk
participants (3)
-
Mike Frysinger
-
Stefan Roese
-
Wolfgang Denk