Skip to contentSkip to conversation

kwbimage.c: Fix compile warning when building on 32/64 bit systems

PATCH New Stefan Roese 3 participants 8 messages Sep 15, 2009 – Sep 18, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

Cc Wolfgang Denk <[email protected]>
Cc Prafulla Wadaskar <[email protected]>
---
 tools/kwbimage.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
tools/kwbimage.c +2 -2
index ee067cb..2c542da 100644
@@ -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;
 	}
 
Signature · 1 line
1.6.4.3
#1 lore raw

PATCH 1/1 kwbimage.c: Fix compile warning when building on 32/64 bit systems

Dear Stefan Roese,

Quoted 5 lines · In message <[email protected]> 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:

Quoted 7 lines

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

Signature · 7 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
I came home the other night and tried to open the door  with  my  car
keys...and  the  building started up. So I took it out for a drive. A
cop pulled me over for speeding. He asked me where I  live...  "Right
here".                                                - Steven Wright
#2 lore raw

PATCH 1/1 kwbimage.c: Fix compile warning when building on 32/64 bit systems

In reply to Stefan Roese
Quoted 13 lines · 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.

tools/kwbimage.c static uint32_t kwbimage_checksum32 (uint32_t *start, uint32_t len, uint32_t csu · line 135

Quoted 5 lines
tools/kwbimage.c +2 -2
 	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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20090915/b100bc92/attachment.pgp

#3 lore raw

PATCH 1/1 kwbimage.c: Fix compile warning when building on 32/64 bit systems

Dear Mike Frysinger,

Quoted 8 lines · In message <[email protected]> you wrote:

tools/kwbimage.c static uint32_t kwbimage_checksum32 (uint32_t *start, uint32_t len, uint32_t csu · line 135

Quoted 6 lines
tools/kwbimage.c +2 -2
 	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".

Quoted 1 line

as well fix the typo in the message ("length") while you're here, and use the

Ah, well spotted. Thanks.

Quoted 1 line

standardized __func__ ...

Well, ok. Next time, maybe ;-)

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
What about WRITING it first and rationalizing it afterwords?  :-)
                       - Larry Wall in <[email protected]>
#4 lore raw

PATCH 1/1 kwbimage.c: Fix compile warning when building on 32/64 bit systems

Quoted 10 lines · On Tuesday 15 September 2009 15:36:54 Wolfgang Denk wrote:
Quoted 8 lines · Mike Frysinger

tools/kwbimage.c static uint32_t kwbimage_checksum32 (uint32_t *start, uint32_t len, uint32_t csu · line 135

Quoted 5 lines
tools/kwbimage.c +2 -2
 	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

Quoted 3 lines

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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20090915/cbdf1122/attachment.pgp

#5 lore raw

PATCH 1/1 kwbimage.c: Fix compile warning when building on 64 bit systems (again)

In reply to Stefan Roese

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.

---
 tools/kwbimage.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/kwbimage.c +1 -1
index ee067cb..b555553 100644
@@ -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;
 	}
Signature · 1 line
1.6.0.6
#6 lore raw

PATCH v2 1/1 kwbimage.c: Fix compile warning when building on 64 bit systems (again)

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.

---
v2: Also fix spelling error; cudos Mike Frysinger

 tools/kwbimage.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/kwbimage.c +1 -1
index ee067cb..7b26920 100644
@@ -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;
 	}
Signature · 1 line
1.6.0.6
#7 lore raw

PATCH v2 1/1 kwbimage.c: Fix compile warning when building on 64 bit systems (again)

Quoted 5 lines · In message <[email protected]> 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.

Quoted 8 lines

Also fix spelling error.

---
v2: Also fix spelling error; cudos Mike Frysinger

 tools/kwbimage.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Applied.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Those who do not  understand  Unix  are  condemned  to  reinvent  it,
poorly.              - Henry Spencer, University of Toronto Unix hack