[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: test-base64 warnings
From: |
Simon Josefsson |
Subject: |
Re: test-base64 warnings |
Date: |
Fri, 30 May 2008 10:38:19 +0200 |
User-agent: |
Gnus/5.110009 (No Gnus v0.9) Emacs/22.2 (gnu/linux) |
Bruno Haible <address@hidden> writes:
> Hi Simon,
>
> While testing the coreutils-6.11.104-00a30 coreutils snapshot on
> MacOS X 10.5, I got these warnings:
>
> test-base64.c: In function 'main':
> test-base64.c:121: warning: format '%d' expects type 'int', but argument 3
> has type 'size_t'
> test-base64.c:131: warning: format '%d' expects type 'int', but argument 3
> has type 'size_t'
> test-base64.c:142: warning: format '%d' expects type 'int', but argument 3
> has type 'size_t'
> test-base64.c:153: warning: format '%d' expects type 'int', but argument 3
> has type 'size_t'
> test-base64.c:164: warning: format '%d' expects type 'int', but argument 3
> has type 'size_t'
> test-base64.c:175: warning: format '%d' expects type 'int', but argument 3
> has type 'size_t'
>
> This indicates actually incorrect test code on 64-bit platforms.
>
> To printf a value of type 'size_t', I usually cast it to 'unsigned long' and
> then use '%lu', not '%d'.
Hi Bruno. Thanks for finding these. For some reason, I can't reproduce
the warnings even with -Wall (gcc 4.2.3). But the warnings seems
correct. Patch below pushed.
(I wish there was a PRI macro for size_t types...)
Thanks,
/Simon
>From 0a9fff2e522a3856ebdc4970ca0ca9b88070c07b Mon Sep 17 00:00:00 2001
From: Simon Josefsson <address@hidden>
Date: Fri, 30 May 2008 10:35:10 +0200
Subject: [PATCH] tests/test-base64.c: Cast size_t to unsigned long when
invoking printf. Use %lu instead of %d.
Reported by Bruno Haible <address@hidden>.
---
ChangeLog | 6 ++++++
tests/test-base64.c | 14 +++++++-------
2 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index dbabf96..12a8136 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-05-30 Simon Josefsson <address@hidden>
+
+ * tests/test-base64.c: Cast size_t to unsigned long when invoking
+ printf. Use %lu instead of %d. Reported by Bruno Haible
+ <address@hidden>.
+
2008-05-29 Eric Blake <address@hidden>
Prefer new POSIX 200x interfaces over futimesat.
diff --git a/tests/test-base64.c b/tests/test-base64.c
index 657ba19..c8b2a2d 100644
--- a/tests/test-base64.c
+++ b/tests/test-base64.c
@@ -1,5 +1,5 @@
/* Self tests for base64.
- Copyright (C) 2004 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2008 Free Software Foundation, Inc.
Written by Simon Josefsson.
This program is free software: you can redistribute it and/or modify
@@ -118,7 +118,7 @@ main (int argc, char *argv[])
if (!ok)
fprintf (stderr, "decode failed\n");
if (len != 0)
- fprintf (stderr, "failure (%d)\n", len);
+ fprintf (stderr, "failure (%ul)\n", (unsigned long) len);
memset (out, 0x42, sizeof (out));
len = 1;
@@ -128,7 +128,7 @@ main (int argc, char *argv[])
if (len != 1 || memcmp (out, "abcdefg", 1) != 0)
{
out[2] = '\0';
- fprintf (stderr, "failure (%d: %s)\n", len, out);
+ fprintf (stderr, "failure (%ul: %s)\n", (unsigned long) len, out);
}
memset (out, 0x42, sizeof (out));
@@ -139,7 +139,7 @@ main (int argc, char *argv[])
if (len != 2 || memcmp (out, "abcdefg", 2) != 0)
{
out[3] = '\0';
- fprintf (stderr, "failure (%d: %s)\n", len, out);
+ fprintf (stderr, "failure (%ul: %s)\n", (unsigned long) len, out);
}
memset (out, 0x42, sizeof (out));
@@ -150,7 +150,7 @@ main (int argc, char *argv[])
if (len != 3 || memcmp (out, "abcdefg", 3) != 0)
{
out[4] = '\0';
- fprintf (stderr, "failure (%d: %s)\n", len, out);
+ fprintf (stderr, "failure (%ul: %s)\n", (unsigned long) len, out);
}
memset (out, 0x42, sizeof (out));
@@ -161,7 +161,7 @@ main (int argc, char *argv[])
if (len != 3 || memcmp (out, "abcdefg", 3) != 0)
{
out[3] = '\0';
- fprintf (stderr, "failure (%d: %s)\n", len, out);
+ fprintf (stderr, "failure (%ul: %s)\n", (unsigned long) len, out);
}
memset (out, 0x42, sizeof (out));
@@ -172,7 +172,7 @@ main (int argc, char *argv[])
if (len != 7 || memcmp (out, "abcdefg", 7) != 0)
{
out[7] = '\0';
- fprintf (stderr, "failure (%d: %s)\n", len, out);
+ fprintf (stderr, "failure (%ul: %s)\n", (unsigned long) len, out);
}
return 0;
--
1.5.5.1