[parisc-linux] Building packages, problems with printf

Steve Beattie steve@wirex.net
Tue, 3 Apr 2001 18:47:00 -0700


On Mon, Mar 26, 2001 at 09:03:34AM +1000, Alan Modra wrote:
> On Sun, 25 Mar 2001, Matthew Wilcox wrote:
> 
> > Something we've been running into when building packages is the problem
> > that printf is defined as a macro when using gcc 2.97.  This should be
> > resolved by doing the following:
> > 
> > #include <stdio.h>
> > #undef printf
> 
> That's cheating!  The real fix is to turn
> 
> printf (foo_string,
> #if SOMETHING
> abc_param
> #else
> xyz_param
> #endif
> );
> 
> into
> 
> #if SOMETHING
> printf (foo_string, abc_param);
> #else
> printf (foo_string, xyz_param);
> #endif

Actually, another solution is:

(printf) (foo_string,
#if SOMETHING
abc_param
#else
xyz_param
#endif
);

The parentheses surrounding printf prevent macro expansion -- the C
standard explicitly states that it must. We discovered this in the
course of developing FormatGuard, a patch to glibc that turns printf
and the like into macros as a means of preventing format string attacks
(see http://www.immunix.org/formatguard.html for details).

-- 
Steve Beattie                               Don't trust programmers? 
<steve@wirex.net>                         Complete StackGuard distro at
http://immunix.org/~steve/                         immunix.org