[Top][All Lists]

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

*** %n in writable segment detected ***

From: Martin Walch
Subject: *** %n in writable segment detected ***
Date: Sat, 14 Feb 2009 01:30:38 +0100
User-agent: KMail/1.11.0 (Linux/2.6.27-gentoo-r8; KDE/4.2.0; x86_64; ; )

Hello list,

first of all: I do not know much about autoconf and autotools. But still there 
is something that I think is going wrong. I do not want to blame anybody for 
anything. I just describe what I see as a problem and I would be happy to hear 
some thoughts about it:

When using rather new versions of glibc (2.8...) and gcc (4.3.3), I get an 
ugly warning on the screen during the execution of some configure scripts like 
the ones from coreutils or m4. It says:

*** %n in writable segment detected ***

and this is a warning that can not be suppressed by redirecting stdout or 
stderr as glibc opens a new tty. The code causing this is basically:

#include <stdio.h>
#include <string.h>
static char fmtstring[10];
static char buf[100];
int main ()
  int count = -1;
  /* Copy the format string.  Some systems (glibc with _FORTIFY_SOURCE=2)
     support %n in format strings in read-only memory but not in writable
     memory.  */
  strcpy (fmtstring, "%d %n");
  if (sprintf (buf, fmtstring, 123, &count, 33, 44, 55) < 0
      || strcmp (buf, "123 ") != 0
      || count != 4)
    return 1;
  return 0;

As soon as basic optimization is turned on (-O1), the warning is thrown.

I think it is a bad idea to get this warning from a configure script. It does 
not appear in config.log but also can not be avoided. It confuses programmers 
and non-programmers. Also, it should be possible to ignore any warning within 
a configure script as it should be save to ignore any warning or error that 
shows up during a check.

Martin Walch

reply via email to

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