bug-bison
[Top][All Lists]
Advanced

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

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


From: Joel E. Denny
Subject: Re: [PATCH] build: avoid printf format mismatch warnings
Date: Tue, 29 Sep 2009 07:09:52 -0400 (EDT)
User-agent: Alpine 1.00 (DEB 882 2007-12-20)

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 <address@hidden>
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  <address@hidden>
+
+       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  <address@hidden>
 
        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





reply via email to

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