Skip to contentSkip to conversation

common: fix compiler warning on wrong printf format

PATCH Superseded Alexey Brodkin 3 participants 3 messages Aug 26, 2014 – Aug 28, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common: fix compiler warning on wrong printf format

bounce_buffer->len_aligned is of type "size_t", but on some arches/compilers "size_t" might be an alias to whether "int", "long" or their "signed/unsigned" flavors.

So to make compiler happy we explicitly cast to "int" which is expected in printf for "%d" format.

this fixes following warning:
--->---
common/bouncebuf.c: In function ?addr_aligned?:
common/bouncebuf.c:26:3: warning: format ?%d? expects argument of type ?int?, but argument 2 has type ?size_t? [-Wformat=]
debug("Unaligned buffer length %d\n", /*(int)*/state->len);
^
--->---

---
 common/bouncebuf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
common/bouncebuf.c +1 -1
index 9eece6d..0828d4b 100644
@@ -23,7 +23,7 @@ static int addr_aligned(struct bounce_buffer *state)
 
 	/* Check if length is aligned */
 	if (state->len != state->len_aligned) {
-		debug("Unaligned buffer length %d\n", state->len);
+		debug("Unaligned buffer length %d\n", (int)state->len);
 		return 0;
 	}
 
Signature · 1 line
1.9.3
#1 lore raw

PATCH 1/1 common: fix compiler warning on wrong printf format

Quoted 27 lines · Alexey Brodkin

bounce_buffer->len_aligned is of type "size_t", but on some arches/compilers "size_t" might be an alias to whether "int", "long" or their "signed/unsigned" flavors.

So to make compiler happy we explicitly cast to "int" which is expected in printf for "%d" format.

this fixes following warning:
--->---
common/bouncebuf.c: In function ?addr_aligned?:
common/bouncebuf.c:26:3: warning: format ?%d? expects argument of type ?int?, but argument 2 has type ?size_t? [-Wformat=]

   debug("Unaligned buffer length %d\n", /*(int)*/state->len);
   ^

--->---

---
 common/bouncebuf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
common/bouncebuf.c +0 -0
index 9eece6d..0828d4b 100644

common/bouncebuf.c static int addr_aligned(struct bounce_buffer *state) · line 26

Quoted 5 lines
common/bouncebuf.c +1 -1
@@ -23,7 +23,7 @@ static int addr_aligned(struct bounce_buffer *state)
 
        /* Check if length is aligned */
        if (state->len != state->len_aligned) {
-               debug("Unaligned buffer length %d\n", state->len);
+               debug("Unaligned buffer length %d\n", (int)state->len);

Another way of fixing this would be to use %zu or %zd instead of %d. Although that is a C99 addition so I'm not sure how much people care about really old compilers.

http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf section 7.19.6.1 if anyone really cares.

Quoted 10 lines
common/bouncebuf.c +0 -1
                return 0;
        }
 
--

1.9.3

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#2 lore raw

PATCH 1/1 common: fix compiler warning on wrong printf format

Quoted 30 lines · Chris Packham
Quoted 28 lines · Alexey Brodkin

bounce_buffer->len_aligned is of type "size_t", but on some arches/compilers "size_t" might be an alias to whether "int", "long" or their "signed/unsigned" flavors.

So to make compiler happy we explicitly cast to "int" which is expected in printf for "%d" format.

this fixes following warning:
--->---
common/bouncebuf.c: In function ?addr_aligned?:
common/bouncebuf.c:26:3: warning: format ?%d? expects argument of type ?int?, but argument 2 has type ?size_t? [-Wformat=]

   debug("Unaligned buffer length %d\n", /*(int)*/state->len);
   ^

--->---

---
 common/bouncebuf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
common/bouncebuf.c +0 -0
index 9eece6d..0828d4b 100644
@@ -23,7 +23,7 @@ static int addr_aligned(struct bounce_buffer *state)
 
Quoted 8 lines

common/bouncebuf.c static int addr_aligned(struct bounce_buffer *state) · line 26

Quoted 4 lines
common/bouncebuf.c +1 -1
        /* Check if length is aligned */
        if (state->len != state->len_aligned) {
-               debug("Unaligned buffer length %d\n", state->len);
+               debug("Unaligned buffer length %d\n", (int)state->len);

Another way of fixing this would be to use %zu or %zd instead of %d. Although that is a C99 addition so I'm not sure how much people care about really old compilers.

And %zd has other usages in the codebase so please use that, thanks.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140828/cec28d04/attachment.pgp>