[PATCH] build: avoid printf format mismatch warnings

View: New views
14 Messages — Rating Filter:   Alert me  

[PATCH] build: avoid printf format mismatch warnings

by Jim Meyering :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello!

I tried to bootstrap/build "master" today, without
success, so switched to branch-2.5.  There, ./bootstrap
succeeded, but the build failed with two like this:

  Sbitset.c: In function 'Sbitset__fprint':
  Sbitset.c:75: error: format '%d' expects type 'int', but argument 3
    has type 'Sbitset__Index

With the change below, the build and "make check" succeeded.

From 25d058425a0a332c5eb4a4dc8914705617efe566 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@...>
Date: Tue, 29 Sep 2009 08:17:37 +0200
Subject: [PATCH] build: avoid printf format mismatch warnings

* src/Sbitset.c (Sbitset__fprint): Cast Sbitset__Index to "int"
when printing.
---
 ChangeLog     |    6 ++++++
 src/Sbitset.c |    4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4b233db..72588ee 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2009-09-29  Jim Meyering  <meyering@...>
+
+ build: avoid printf format mismatch warnings
+ * src/Sbitset.c (Sbitset__fprint): Cast Sbitset__Index to "int"
+ when printing.
+
 2009-09-27  Joel E. Denny  <jdenny@...>

  tests: don't abuse AT_BISON_CHECK.
diff --git a/src/Sbitset.c b/src/Sbitset.c
index 0c1fedf..145a72a 100644
--- a/src/Sbitset.c
+++ b/src/Sbitset.c
@@ -65,14 +65,14 @@ Sbitset__fprint(Sbitset self, Sbitset__Index nbits, FILE *file)
   Sbitset__Index i;
   Sbitset itr;
   bool first = true;
-  fprintf (file, "nbits = %d, set = {", nbits);
+  fprintf (file, "nbits = %d, set = {", (int) nbits);
   SBITSET__FOR_EACH (self, nbits, itr, i)
     {
       if (first)
         first = false;
       else
         fprintf (file, ",");
-      fprintf (file, " %d", i);
+      fprintf (file, " %d", (int) i);
     }
   fprintf (file, " }");
 }
--
1.6.5.rc2.177.ga9dd6



Re: [PATCH] build: avoid printf format mismatch warnings

by Joel E. Denny-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Jim.

On Tue, 29 Sep 2009, Jim Meyering wrote:

> I tried to bootstrap/build "master" today, without
> success, so switched to branch-2.5.  There, ./bootstrap
> succeeded, but the build failed with two like this:
>
>   Sbitset.c: In function 'Sbitset__fprint':
>   Sbitset.c:75: error: format '%d' expects type 'int', but argument 3
>     has type 'Sbitset__Index

Thanks for the report.  I'm not seeing those failures with either gcc
4.2.4 or 4.3.4.  Which gcc are you using?

> With the change below, the build and "make check" succeeded.

>    Sbitset__Index i;
>    Sbitset itr;
>    bool first = true;
> -  fprintf (file, "nbits = %d, set = {", nbits);
> +  fprintf (file, "nbits = %d, set = {", (int) nbits);
>    SBITSET__FOR_EACH (self, nbits, itr, i)
>      {
>        if (first)
>          first = false;
>        else
>          fprintf (file, ",");
> -      fprintf (file, " %d", i);
> +      fprintf (file, " %d", (int) i);
>      }
>    fprintf (file, " }");
>  }

Because Sbitset__index is a size_t, wouldn't the following patch be
better?

From 47eced3099712180364f4e01b839242027d9a9d8 Mon Sep 17 00:00:00 2001
From: Joel E. Denny <jdenny@...>
Date: Tue, 29 Sep 2009 06:54:38 -0400
Subject: [PATCH] Use the correct conversion specifier for size_t.

Reported by Jim Meyering.
* src/Sbitset.h (SBITSET__INDEX__CONVERSION_SPEC): New, "zu"
because Sbitset__Index is size_t.
* src/Sbitset.c (Sbitset__fprint): Use it instead of %d.
---
 ChangeLog     |    8 ++++++++
 src/Sbitset.c |    6 ++++--
 src/Sbitset.h |    1 +
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a0b4314..1b0bb87 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-09-29  Joel E. Denny  <jdenny@...>
+
+ Use the correct conversion specifier for size_t.
+ Reported by Jim Meyering.
+ * src/Sbitset.h (SBITSET__INDEX__CONVERSION_SPEC): New, "zu"
+ because Sbitset__Index is size_t.
+ * src/Sbitset.c (Sbitset__fprint): Use it instead of %d.
+
 2009-09-27  Joel E. Denny  <jdenny@...>
 
  tests: don't abuse AT_BISON_CHECK.
diff --git a/src/Sbitset.c b/src/Sbitset.c
index 0c1fedf..af8600b 100644
--- a/src/Sbitset.c
+++ b/src/Sbitset.c
@@ -65,14 +65,16 @@ Sbitset__fprint(Sbitset self, Sbitset__Index nbits, FILE *file)
   Sbitset__Index i;
   Sbitset itr;
   bool first = true;
-  fprintf (file, "nbits = %d, set = {", nbits);
+  fprintf (file,
+           "nbits = %" SBITSET__INDEX__CONVERSION_SPEC ", set = {",
+           nbits);
   SBITSET__FOR_EACH (self, nbits, itr, i)
     {
       if (first)
         first = false;
       else
         fprintf (file, ",");
-      fprintf (file, " %d", i);
+      fprintf (file, " %" SBITSET__INDEX__CONVERSION_SPEC, i);
     }
   fprintf (file, " }");
 }
diff --git a/src/Sbitset.h b/src/Sbitset.h
index 4b4b750..a025040 100644
--- a/src/Sbitset.h
+++ b/src/Sbitset.h
@@ -22,6 +22,7 @@
 
 typedef char *Sbitset;
 typedef size_t Sbitset__Index;
+#define SBITSET__INDEX__CONVERSION_SPEC "zu"
 
 #define Sbitset__nbytes(NBITS)            (((NBITS)+7)/8)
 #define Sbitset__byteAddress(SELF, INDEX) (((SELF) + (INDEX)/8))
--
1.5.4.3




Re: [PATCH] build: avoid printf format mismatch warnings

by Jim Meyering :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Joel E. Denny wrote:

> On Tue, 29 Sep 2009, Jim Meyering wrote:
>> I tried to bootstrap/build "master" today, without
>> success, so switched to branch-2.5.  There, ./bootstrap
>> succeeded, but the build failed with two like this:
>>
>>   Sbitset.c: In function 'Sbitset__fprint':
>>   Sbitset.c:75: error: format '%d' expects type 'int', but argument 3
>>     has type 'Sbitset__Index
>
> Thanks for the report.  I'm not seeing those failures with either gcc
> 4.2.4 or 4.3.4.  Which gcc are you using?

Hi Joel,

I'm using the stock gcc on an up-to-date Fedora 11 system:

  gcc version 4.4.1 20090725 (Red Hat 4.4.1-2) (GCC)

>> With the change below, the build and "make check" succeeded.
...

>> -      fprintf (file, " %d", i);
>> +      fprintf (file, " %d", (int) i);
>>      }
>>    fprintf (file, " }");
>>  }
>
> Because Sbitset__index is a size_t, wouldn't the following patch be
> better?
>
>>From 47eced3099712180364f4e01b839242027d9a9d8 Mon Sep 17 00:00:00 2001
> From: Joel E. Denny <jdenny@...>
> Date: Tue, 29 Sep 2009 06:54:38 -0400
> Subject: [PATCH] Use the correct conversion specifier for size_t.
>
> Reported by Jim Meyering.
> * src/Sbitset.h (SBITSET__INDEX__CONVERSION_SPEC): New, "zu"
> because Sbitset__Index is size_t.
> * src/Sbitset.c (Sbitset__fprint): Use it instead of %d.
...
> -      fprintf (file, " %d", i);
> +      fprintf (file, " %" SBITSET__INDEX__CONVERSION_SPEC, i);
...
> +#define SBITSET__INDEX__CONVERSION_SPEC "zu"

I didn't know (and didn't dig) if it could be negative,
presumed that the author chose %d for a good reason,
and took the quick and dirty add-cast approach.

I'm glad there was a better say.



Re: [PATCH] build: avoid printf format mismatch warnings

by Joel E. Denny-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 29 Sep 2009, Jim Meyering wrote:

> I'm using the stock gcc on an up-to-date Fedora 11 system:
>
>   gcc version 4.4.1 20090725 (Red Hat 4.4.1-2) (GCC)

I'm building that and will try it soon.

> > Because Sbitset__index is a size_t, wouldn't the following patch be
> > better?

> I didn't know (and didn't dig) if it could be negative,
> presumed that the author chose %d for a good reason,

Nope, I was the author, and I was being sloppy.  :)

> I'm glad there was a better say.

Thanks again for the report.  I pushed that patch to master and
branch-2.5.



Re: [PATCH] build: avoid printf format mismatch warnings

by Eric Blake :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Joel E. Denny <jdenny <at> clemson.edu> writes:

> Because Sbitset__index is a size_t, wouldn't the following patch be
> better?
>
> -  fprintf (file, "nbits = %d, set = {", nbits);
> +  fprintf (file,
> +           "nbits = %" SBITSET__INDEX__CONVERSION_SPEC ", set = {",
> +           nbits);
>
>  typedef char *Sbitset;
>  typedef size_t Sbitset__Index;
> +#define SBITSET__INDEX__CONVERSION_SPEC "zu"

For this to work on all platforms, you need the gnulib module fprintf-posix
(sadly, %zu is not completely portable yet).

--
Eric Blake






Re: [PATCH] build: avoid printf format mismatch warnings

by Joel E. Denny-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 29 Sep 2009, Jim Meyering wrote:

> Joel E. Denny wrote:
> > On Tue, 29 Sep 2009, Jim Meyering wrote:
> >> I tried to bootstrap/build "master" today, without
> >> success, so switched to branch-2.5.  There, ./bootstrap
> >> succeeded, but the build failed with two like this:
> >>
> >>   Sbitset.c: In function 'Sbitset__fprint':
> >>   Sbitset.c:75: error: format '%d' expects type 'int', but argument 3
> >>     has type 'Sbitset__Index
> >
> > Thanks for the report.  I'm not seeing those failures with either gcc
> > 4.2.4 or 4.3.4.  Which gcc are you using?
>
> Hi Joel,
>
> I'm using the stock gcc on an up-to-date Fedora 11 system:
>
>   gcc version 4.4.1 20090725 (Red Hat 4.4.1-2) (GCC)

I built gcc 4.4.1 from source.  I built Bison master and branch-2.5
(before applying the Sbitset patch) with it, but I did not see any
failures.

Is there anything else in your environment that might matter?  Do you set
CFLAGS, for example?

It would be nice to know where this is coming from so we can catch future
problems.



Re: [PATCH] build: avoid printf format mismatch warnings

by Jim Meyering :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Joel E. Denny wrote:

> On Tue, 29 Sep 2009, Jim Meyering wrote:
>
>> Joel E. Denny wrote:
>> > On Tue, 29 Sep 2009, Jim Meyering wrote:
>> >> I tried to bootstrap/build "master" today, without
>> >> success, so switched to branch-2.5.  There, ./bootstrap
>> >> succeeded, but the build failed with two like this:
>> >>
>> >>   Sbitset.c: In function 'Sbitset__fprint':
>> >>   Sbitset.c:75: error: format '%d' expects type 'int', but argument 3
>> >>     has type 'Sbitset__Index
>> >
>> > Thanks for the report.  I'm not seeing those failures with either gcc
>> > 4.2.4 or 4.3.4.  Which gcc are you using?
>>
>> Hi Joel,
>>
>> I'm using the stock gcc on an up-to-date Fedora 11 system:
>>
>>   gcc version 4.4.1 20090725 (Red Hat 4.4.1-2) (GCC)
>
> I built gcc 4.4.1 from source.  I built Bison master and branch-2.5
> (before applying the Sbitset patch) with it, but I did not see any
> failures.
>
> Is there anything else in your environment that might matter?  Do you set
> CFLAGS, for example?
>
> It would be nice to know where this is coming from so we can catch future
> problems.

I configured with --enable-gcc-warnings (of course!  doesn't everybody? ;-)



Re: [PATCH] build: avoid printf format mismatch warnings

by Joel E. Denny-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 29 Sep 2009, Jim Meyering wrote:

> Joel E. Denny wrote:
>
> > On Tue, 29 Sep 2009, Jim Meyering wrote:
> >
> >> Joel E. Denny wrote:
> >> > On Tue, 29 Sep 2009, Jim Meyering wrote:
> >> >> I tried to bootstrap/build "master" today, without
> >> >> success, so switched to branch-2.5.  There, ./bootstrap
> >> >> succeeded, but the build failed with two like this:
> >> >>
> >> >>   Sbitset.c: In function 'Sbitset__fprint':
> >> >>   Sbitset.c:75: error: format '%d' expects type 'int', but argument 3
> >> >>     has type 'Sbitset__Index
> >> >
> >> > Thanks for the report.  I'm not seeing those failures with either gcc
> >> > 4.2.4 or 4.3.4.  Which gcc are you using?
> >>
> >> Hi Joel,
> >>
> >> I'm using the stock gcc on an up-to-date Fedora 11 system:
> >>
> >>   gcc version 4.4.1 20090725 (Red Hat 4.4.1-2) (GCC)
> >
> > I built gcc 4.4.1 from source.  I built Bison master and branch-2.5
> > (before applying the Sbitset patch) with it, but I did not see any
> > failures.
> >
> > Is there anything else in your environment that might matter?  Do you set
> > CFLAGS, for example?
> >
> > It would be nice to know where this is coming from so we can catch future
> > problems.
>
> I configured with --enable-gcc-warnings (of course!  doesn't everybody? ;-)

I always do too, but I still didn't see the failures.

Also, it looks like you got a hard error instead of a warning being
treated as an error, so I'm not completely sure that --enable-gcc-warnings
matters.

With the following test program, I haven't persuaded gcc to give me a
warning or error:

% cat >tmp.c <<EOF
#include <stdio.h>
int
main (void)
{
  size_t i = 0;
  printf ("%d\n", i);
  return 0;
}
EOF
% gcc -std=gnu99 -Wall -Wextra -Wno-sign-compare -Wcast-align -Wcast-qual -Wformat -Wpointer-arith -Wwrite-strings -Wbad-function-cast -Wmissing-declarations -Wmissing-prototypes -Wshadow -Wstrict-prototypes -Werror tmp.c

Any ideas?



Re: [PATCH] build: avoid printf format mismatch warnings

by Jim Meyering :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Joel E. Denny wrote:

> On Tue, 29 Sep 2009, Jim Meyering wrote:
>
>> Joel E. Denny wrote:
>>
>> > On Tue, 29 Sep 2009, Jim Meyering wrote:
>> >
>> >> Joel E. Denny wrote:
>> >> > On Tue, 29 Sep 2009, Jim Meyering wrote:
>> >> >> I tried to bootstrap/build "master" today, without
>> >> >> success, so switched to branch-2.5.  There, ./bootstrap
>> >> >> succeeded, but the build failed with two like this:
>> >> >>
>> >> >>   Sbitset.c: In function 'Sbitset__fprint':
>> >> >>   Sbitset.c:75: error: format '%d' expects type 'int', but argument 3
>> >> >>     has type 'Sbitset__Index
>> >> >
>> >> > Thanks for the report.  I'm not seeing those failures with either gcc
>> >> > 4.2.4 or 4.3.4.  Which gcc are you using?
>> >>
>> >> Hi Joel,
>> >>
>> >> I'm using the stock gcc on an up-to-date Fedora 11 system:
>> >>
>> >>   gcc version 4.4.1 20090725 (Red Hat 4.4.1-2) (GCC)
>> >
>> > I built gcc 4.4.1 from source.  I built Bison master and branch-2.5
>> > (before applying the Sbitset patch) with it, but I did not see any
>> > failures.
>> >
>> > Is there anything else in your environment that might matter?  Do you set
>> > CFLAGS, for example?
>> >
>> > It would be nice to know where this is coming from so we can catch future
>> > problems.
>>
>> I configured with --enable-gcc-warnings (of course!  doesn't everybody? ;-)
>
> I always do too, but I still didn't see the failures.
>
> Also, it looks like you got a hard error instead of a warning being
> treated as an error, so I'm not completely sure that --enable-gcc-warnings
> matters.
>
> With the following test program, I haven't persuaded gcc to give me a
> warning or error:
>
> % cat >tmp.c <<EOF
> #include <stdio.h>
> int
> main (void)
> {
>   size_t i = 0;
>   printf ("%d\n", i);
>   return 0;
> }
> EOF
> % gcc -std=gnu99 -Wall -Wextra -Wno-sign-compare -Wcast-align -Wcast-qual -Wformat -Wpointer-arith -Wwrite-strings -Wbad-function-cast -Wmissing-declarations -Wmissing-prototypes -Wshadow -Wstrict-prototypes -Werror tmp.c

That works as expected for me.
Here's the output I get:

  cc1: warnings being treated as errors
  tmp.c: In function ‘main’:
  tmp.c:6: error: format ‘%d’ expects type ‘int’, but argument 2 has type ‘size_t’

> Any ideas?

Upgrade to Fedora 11? ;-)

If you built gcc from source, did you run "make check"
and ensure that all of the tests passed?



Re: [PATCH] build: avoid printf format mismatch warnings

by njoly-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Sep 29, 2009 at 01:14:05PM -0400, Joel E. Denny wrote:
[...]

> With the following test program, I haven't persuaded gcc to give me a
> warning or error:
>
> % cat >tmp.c <<EOF
> #include <stdio.h>
> int
> main (void)
> {
>   size_t i = 0;
>   printf ("%d\n", i);
>   return 0;
> }
> EOF
> % gcc -std=gnu99 -Wall -Wextra -Wno-sign-compare -Wcast-align -Wcast-qual -Wformat -Wpointer-arith -Wwrite-strings -Wbad-function-cast -Wmissing-declarations -Wmissing-prototypes -Wshadow -Wstrict-prototypes -Werror tmp.c
>
> Any ideas?

You'll have a warning on archs where sizeof(size_t) != sizeof(int)
such as x86_64 ...

njoly@ [~]> uname -a
Linux xxx.xxx.xxx.xxx 2.6.18-164.el5 #1 SMP Thu Sep 3 03:28:30 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux

When generating 64-bit binary,

njoly@ [~]> gcc -m64 -std=gnu99 -Wall -Wextra -Wno-sign-compare -Wcast-align -Wcast-qual -Wformat -Wpointer-arith -Wwrite-strings -Wbad-function-cast -Wmissing-declarations -Wmissing-prototypes -Wshadow -Wstrict-prototypes -Werror tmp.c
cc1: warnings being treated as errors
tmp.c: In function 'main':
tmp.c:6: warning: format '%d' expects type 'int', but argument 2 has type 'size_t'

But not with 32-bit,

njoly@ [~]> gcc -m32 -std=gnu99 -Wall -Wextra -Wno-sign-compare -Wcast-align -Wcast-qual -Wformat -Wpointer-arith -Wwrite-strings -Wbad-function-cast -Wmissing-declarations -Wmissing-prototypes -Wshadow -Wstrict-prototypes -Werror tmp.c

--
Nicolas Joly

Biological Software and Databanks.
Institut Pasteur, Paris.



Re: [PATCH] build: avoid printf format mismatch warnings

by Jim Meyering :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Nicolas Joly wrote:

> On Tue, Sep 29, 2009 at 01:14:05PM -0400, Joel E. Denny wrote:
> [...]
>> With the following test program, I haven't persuaded gcc to give me a
>> warning or error:
>>
>> % cat >tmp.c <<EOF
>> #include <stdio.h>
>> int
>> main (void)
>> {
>>   size_t i = 0;
>>   printf ("%d\n", i);
>>   return 0;
>> }
>> EOF
>> % gcc -std=gnu99 -Wall -Wextra -Wno-sign-compare -Wcast-align -Wcast-qual -Wformat -Wpointer-arith -Wwrite-strings -Wbad-function-cast -Wmissing-declarations -Wmissing-prototypes -Wshadow -Wstrict-prototypes -Werror tmp.c
>>
>> Any ideas?
>
> You'll have a warning on archs where sizeof(size_t) != sizeof(int)
> such as x86_64 ...

I think you've nailed it.
That's definitely why it's happening for me.  I'm using x86_64.
Mustn't forget that systems with 32-bit size_t still exist.



Re: [PATCH] build: avoid printf format mismatch warnings

by Joel E. Denny-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Eric.

On Tue, 29 Sep 2009, Eric Blake wrote:

> For this to work on all platforms, you need the gnulib module fprintf-posix
> (sadly, %zu is not completely portable yet).

Thanks for pointing that out.

While we're on the topic and I already have two experts watching this
thread, is snprintf-posix helpful in order to use the following portably?

  length = snprintf (NULL, 0, format, args);
  str = malloc (length + 1);
  snprintf (str, length + 1, format, args);

The snprintf man page warns of portability problems here, but
snprintf-posix only appears to test vsnprintf's functionality for this
purpose by invoking gl_VSNPRINTF_ZEROSIZE_C99.  Is it just assumed
snprintf and vsnprintf will be consistent in this respect?

Also, is there any single module that ensures portability of all *printf
functions, or should I include every *printf-posix module individually in
order to ensure consistent behavior?

If I should add bug-gnulib, let me know.



Re: [PATCH] build: avoid printf format mismatch warnings

by Joel E. Denny-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 29 Sep 2009, Jim Meyering wrote:

> Nicolas Joly wrote:
> > On Tue, Sep 29, 2009 at 01:14:05PM -0400, Joel E. Denny wrote:
> > [...]
> >> With the following test program, I haven't persuaded gcc to give me a
> >> warning or error:
> >>
> >> % cat >tmp.c <<EOF
> >> #include <stdio.h>
> >> int
> >> main (void)
> >> {
> >>   size_t i = 0;
> >>   printf ("%d\n", i);
> >>   return 0;
> >> }
> >> EOF
> >> % gcc -std=gnu99 -Wall -Wextra -Wno-sign-compare -Wcast-align -Wcast-qual -Wformat -Wpointer-arith -Wwrite-strings -Wbad-function-cast -Wmissing-declarations -Wmissing-prototypes -Wshadow -Wstrict-prototypes -Werror tmp.c
> >>
> >> Any ideas?
> >
> > You'll have a warning on archs where sizeof(size_t) != sizeof(int)
> > such as x86_64 ...
>
> I think you've nailed it.

Yep.  Thanks Nicolas.



Re: [PATCH] build: avoid printf format mismatch warnings

by Joel E. Denny-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 29 Sep 2009, Joel E. Denny wrote:

> On Tue, 29 Sep 2009, Eric Blake wrote:
>
> > For this to work on all platforms, you need the gnulib module fprintf-posix
> > (sadly, %zu is not completely portable yet).
>
> Thanks for pointing that out.

> Also, is there any single module that ensures portability of all *printf
> functions, or should I include every *printf-posix module individually in
> order to ensure consistent behavior?

I wrote bug-gnulib:

  http://lists.gnu.org/archive/html/bug-gnulib/2009-10/msg00108.html

Based on that discussion, I'm thinking of pushing the following.  I'm
hesitating for a few reasons:

1. I'm not sure why bootstrap.conf was careful to exclude
m4/printf-posix.m4.  Maybe to avoid bloat?

2. -DGNULIB_POSIXCHECK suggests realloc-posix for the sake of
vasnprintf.c, so it seems realloc-posix ought to be a dependency of
vasnprintf-posix.  I'll explore further later and maybe take it to the
gnulib maintainers.

3. -DGNULIB_POSIXCHECK is suggesting a lot of other modules.  We need to
explore those at some point.

4. I'm trying to decide whether to apply the patch to branch-2.4.2.

From dc96d0cbdb17dee59920ad8eb9732213ccb99a84 Mon Sep 17 00:00:00 2001
From: Joel E. Denny <jdenny@...>
Date: Sun, 11 Oct 2009 19:44:14 -0400
Subject: [PATCH] portability: use -DGNULIB_POSIXCHECK.

Reported by Eric Blake.  See discussions at
<http://lists.gnu.org/archive/html/bug-bison/2009-09/msg00008.html>
and
<http://lists.gnu.org/archive/html/bug-gnulib/2009-10/msg00108.html>.
* HACKING (Release checks): Suggest -DGNULIB_POSIXCHECK.
* bootstrap.conf (gnulib_modules): Add all the printf modules
suggested by -DGNULIB_POSIXCHECK.  Add realloc-posix as
suggested by -DGNULIB_POSIXCHECK for gnulib's own vasnprintf.c.
(excluded_files): Remove m4/printf-posix.m4.
---
 ChangeLog      |   13 +++++++++++++
 HACKING        |    3 +++
 bootstrap.conf |   10 ++++++----
 lib/.cvsignore |   44 ++++++++++++++++++++++++++++++++++++++++++++
 lib/.gitignore |   44 ++++++++++++++++++++++++++++++++++++++++++++
 m4/.cvsignore  |   34 ++++++++++++++++++++++++++++++++++
 m4/.gitignore  |   34 ++++++++++++++++++++++++++++++++++
 7 files changed, 178 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a0e138d..c486a3e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2009-10-11  Joel E. Denny  <jdenny@...>
 
+ portability: use -DGNULIB_POSIXCHECK.
+ Reported by Eric Blake.  See discussions at
+ <http://lists.gnu.org/archive/html/bug-bison/2009-09/msg00008.html>
+ and
+ <http://lists.gnu.org/archive/html/bug-gnulib/2009-10/msg00108.html>.
+ * HACKING (Release checks): Suggest -DGNULIB_POSIXCHECK.
+ * bootstrap.conf (gnulib_modules): Add all the printf modules
+ suggested by -DGNULIB_POSIXCHECK.  Add realloc-posix as
+ suggested by -DGNULIB_POSIXCHECK for gnulib's own vasnprintf.c.
+ (excluded_files): Remove m4/printf-posix.m4.
+
+2009-10-11  Joel E. Denny  <jdenny@...>
+
  portability: use va_start and va_end in the same function.
  * src/complain.c (error_message): Move va_end from here...
  (ERROR_MESSAGE): ... to here.
diff --git a/HACKING b/HACKING
index 82f07bb..4edb98b 100644
--- a/HACKING
+++ b/HACKING
@@ -172,6 +172,9 @@ release:
   that 1. Bison compiles cleanly, 2. the parsers it produces compile
   cleanly too.
 
+- Build with -DGNULIB_POSIXCHECK.  It suggests gnulib modules that can
+  fix portability issues.
+
 - run `make maintainer-check' which:
   - runs `valgrind -q bison' to run Bison under Valgrind.
   - runs the parsers under Valgrind.
diff --git a/bootstrap.conf b/bootstrap.conf
index 1cef2f0..a1a4518 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -20,9 +20,12 @@ gnulib_modules='
   announce-gen argmatch config-h c-strcase configmake dirname error
   extensions fopen-safer gendocs getopt-gnu gettext git-version-gen hash
   inttypes javacomp-script javaexec-script maintainer-makefile malloc
-  mbswidth obstack quote quotearg stdbool stpcpy strerror strtoul
-  strverscmp unistd unistd-safer unlocked-io update-copyright unsetenv
-  verify warnings xalloc xalloc-die xstrndup
+  mbswidth obstack quote quotearg realloc-posix stdbool stpcpy strerror
+  strtoul strverscmp unistd unistd-safer unlocked-io update-copyright
+  unsetenv verify warnings xalloc xalloc-die xstrndup
+
+  fprintf-posix printf-posix snprintf-posix sprintf-posix
+  vsnprintf-posix vsprintf-posix
 '
 
 # Additional xgettext options to use.  Use "\\\newline" to break lines.
@@ -52,7 +55,6 @@ excluded_files='
     m4/lcmessage.m4
     m4/lock.m4
     m4/longdouble.m4
-    m4/printf-posix.m4
     m4/signed.m4
     m4/size_max.m4
     m4/uintmax_t.m4