From owner-freebsd-hackers@FreeBSD.ORG Wed Mar 30 18:12:11 2005 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7D52216A4CE for ; Wed, 30 Mar 2005 18:12:11 +0000 (GMT) Received: from mailhost.stack.nl (vaak.stack.nl [131.155.140.140]) by mx1.FreeBSD.org (Postfix) with ESMTP id 815F943D54 for ; Wed, 30 Mar 2005 18:12:10 +0000 (GMT) (envelope-from marcolz@stack.nl) Received: from hammer.stack.nl (hammer.stack.nl [IPv6:2001:610:1108:5010::153]) by mailhost.stack.nl (Postfix) with ESMTP id 3411C1F007 for ; Wed, 30 Mar 2005 20:12:09 +0200 (CEST) Received: by hammer.stack.nl (Postfix, from userid 333) id 054086433; Wed, 30 Mar 2005 20:12:08 +0200 (CEST) Date: Wed, 30 Mar 2005 20:12:08 +0200 From: Marc Olzheim To: freebsd-hackers@freebsd.org Message-ID: <20050330181208.GA64275@stack.nl> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="8t9RHnE3ZwKMSgU+" Content-Disposition: inline X-Operating-System: FreeBSD hammer.stack.nl 5.4-PRERELEASE FreeBSD 5.4-PRERELEASE X-URL: http://www.stack.nl/~marcolz/ User-Agent: Mutt/1.5.9i Subject: Making gcc "-Wformat" more verbose X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Mar 2005 18:12:11 -0000 --8t9RHnE3ZwKMSgU+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi. When programming, I'd like to be able to make sure that what I think what the code that I type does, is what I want it to do. Who doesn't? Anyway, since I'm already compiling with most warnings on and I'm linting my code, I'm trying my best to be more sure of it. There where I find problems that could have been detected by my tools, but weren't, I'd like to make sure that the tools get updated. This prompted me to produce a patch for FreeBSD 5-STABLE's GCC (3.4.2). GCC 3.4.2 takes a shortcut in checking the argument to printf()-like functions with -Wformat. Since arguments to a varargs function smaller than an int are promoted to an int (and floats to double), the check doesn't care what the types originally passed to the function were exactly, as long as after promotion it is good enough. To make things worse, "good enough" here doesn't include checking the signdness. I've made a simple copy-paste patch that makes sure that arguments to those functions are checked _before_ _and_ _after_ the varargs-promotion and that their sign meets the formatstring. Please have a look at it and tell me whether this could be useful for FreeBSD or whether that's a bridge too far... The patch is at http://www.stack.nl/~marcolz/FreeBSD/gcc-printf.patch.txt Besides that, you'll need to include the inttypes.h at http://www.stack.nl/~marcolz/FreeBSD/inttypes.h instead of /usr/include/inttypes.h If you want to compile the kernel with it, make sure to turn of -Werror... (Or install into somewhere else then /usr/libexec and use CFLAGS=-B to gcc to try it out. I know, that other varargs functions' handling isn't modified yet; I just thought I'd start with printf() and see whether it was useful. Please let me know what you think. Marc --8t9RHnE3ZwKMSgU+ Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (FreeBSD) iD8DBQFCSuv4ezjnobFOgrERAi2ZAJ9/KSpapa8iSLWnVVmsLnZZ8qPrWgCgs04s vUgWXAGbikDQ7YRH2MFyJg0= =42HX -----END PGP SIGNATURE----- --8t9RHnE3ZwKMSgU+--