bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] tests/test-vasprintf.c: Test %08lx.


From: Bruno Haible
Subject: Re: [PATCH] tests/test-vasprintf.c: Test %08lx.
Date: Sat, 24 Apr 2010 18:02:42 +0200
User-agent: KMail/1.9.9

Hi Simon,

> > It matters if you are asking to
> > print a 64-bit long, but passed a 32-bit int.  To be safe, you should be
> > using 1L or even 1UL to match the %lx.
> 
> My system is all 32-bit (debian i386 unstable).  Using 1UL or even using
> a 'long int l = 12345' and passing that as a parameter to asprintf
> doesn't change anything.

But there may be 64-bit systems which pass arguments on the stack.
On these platforms, the test would fail (on big-endian ones always,
on little-endian ones with a certain probability). Even though the test does
not fail on Solaris 64-bit (both x86_64 and sparc64), it's worth fixing:

> building this under Cygwin on native Windows works fine.

Confirmed. One more reason to recommend Cygwin for mingw builds: you don't
have to worry whether a bug comes from the Debian packaging, from the fact
that autoconf tests choose the "cross-compiling" alternative, or from Wine.


2010-04-24  Bruno Haible  <address@hidden>

        Avoid a gcc warning.
        * tests/test-vasprintf.c (test_vasprintf, test_asprintf): Pass argument
        of correct type for %08lx directive.
        Reported by Eric Blake.

--- tests/test-vasprintf.c.orig Sat Apr 24 17:52:33 2010
+++ tests/test-vasprintf.c      Sat Apr 24 17:49:47 2010
@@ -60,7 +60,7 @@
   for (repeat = 0; repeat <= 8; repeat++)
     {
       char *result;
-      int retval = my_asprintf (&result, "%08lx", 12345);
+      int retval = my_asprintf (&result, "%08lx", 12345UL);
       ASSERT (retval == 8);
       ASSERT (result != NULL);
       ASSERT (strcmp (result, "00003039") == 0);
@@ -86,7 +86,7 @@
   for (repeat = 0; repeat <= 8; repeat++)
     {
       char *result;
-      int retval = asprintf (&result, "%08lx", 12345);
+      int retval = asprintf (&result, "%08lx", 12345UL);
       ASSERT (retval == 8);
       ASSERT (result != NULL);
       ASSERT (strcmp (result, "00003039") == 0);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]