Linux PARISC architecture development
 help / color / mirror / Atom feed
From: Steve Beattie <steve@wirex.net>
To: parisc-linux@parisc-linux.org
Subject: Re: [parisc-linux] Building packages, problems with printf
Date: Tue, 3 Apr 2001 18:47:00 -0700	[thread overview]
Message-ID: <20010403184700.A8618@wirex.net> (raw)
In-Reply-To: <Pine.LNX.4.21.0103260855260.3568-100000@front.linuxcare.com.au>; from alan@linuxcare.com.au on Mon, Mar 26, 2001 at 09:03:34AM +1000

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

      parent reply	other threads:[~2001-04-04  1:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-25 21:02 [parisc-linux] Building packages, problems with printf Matthew Wilcox
2001-03-25 23:03 ` Alan Modra
2001-03-25 23:11   ` Matthew Wilcox
2001-03-25 23:42   ` Alan Cox
2001-03-25 23:44     ` Matthew Wilcox
2001-04-04  1:47   ` Steve Beattie [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010403184700.A8618@wirex.net \
    --to=steve@wirex.net \
    --cc=parisc-linux@parisc-linux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox