Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 5 Dec 2001 20:00:06 +0000
From:      David Malone <dwmalone@maths.tcd.ie>
To:        Mike Barcroft <mike@freebsd.org>
Cc:        audit@freebsd.org, markm@freebsd.org, Bruce Evans <bde@zeta.org.au>, obrien@freebsd.org
Subject:   Re: Warns for tcopy and wc.
Message-ID:  <20011205200006.A38562@walton.maths.tcd.ie>
In-Reply-To: <20011204112148.F57237@espresso.q9media.com>; from mike@freebsd.org on Tue, Dec 04, 2001 at 11:21:48AM -0500
References:  <20011203215452.E57237@espresso.q9media.com> <200112041341.aa05762@salmon.maths.tcd.ie> <20011204112148.F57237@espresso.q9media.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Dec 04, 2001 at 11:21:48AM -0500, Mike Barcroft wrote:
> David Malone <dwmalone@maths.tcd.ie> writes:
> > I presume casting to intmax_t will be the oficially blessed way of
> > printing typedefed things now? If so we should make gcc's format
> > warning code understand the %j modifier - maybe I should look into
> > that (or maybe some of the FreeBSD standards people are doing that?).
> 
> Yes, intmax_t is guaranteed to be capable of representing any value of
> any signed integer.  Similarly, uintmax_t is guaranteed to be capable
> of representing any value of any unsigned integer.  It would probably
> be a good idea to teach GCC about these types.

The following patch makes gcc think that intmat_t is the same thing
as a long long when it is doing format checking. The list of types
gcc knows for format checking is just after line 1060 of c-common.c
and long long is the closest thing available.

I've included a short shell script which should emit no warnings if
gcc has been patched with this patch. If someone could compile and
install gcc on the alpha with this patch and then run the shell script
to see if it emits a warning, that would be useful.

(I'll try to do it myself, but it is hard to test gcc without
installing it).

	David.


Index: c-common.c
===================================================================
RCS file: /cvs/FreeBSD-CVS/src/contrib/gcc.295/c-common.c,v
retrieving revision 1.12
diff -u -r1.12 c-common.c
--- c-common.c	25 May 2001 19:00:07 -0000	1.12
+++ c-common.c	5 Dec 2001 19:36:02 -0000
@@ -1777,6 +1777,13 @@
 		warning ("ANSI C does not support the `%c' length modifier",
 			 length_char);
 	    }
+	  else if (*format_chars == 'j')
+	    {
+	      length_char = 'q', format_chars++;
+	      if (pedantic)
+		warning ("ANSI C does not support the `%c' length modifier",
+			 length_char);
+	    }
 	  else if (*format_chars == 'Z')
 	    {
 	      length_char = *format_chars++;


#!/bin/sh

cat > jtest.c <<EOF
#include <stdio.h>
#include <stdint.h>
int main() { intmax_t a=0; printf("%jd", a); return 0; }
EOF

gcc -W -Wall -o jtest jtest.c
rm -f jtest.c jtest


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011205200006.A38562>