c/8194: sprintf causes segfaults

finch@clara.co.uk finch@clara.co.uk
Thu Oct 10 17:16:00 GMT 2002

>Number:         8194
>Category:       c
>Synopsis:       sprintf causes segfaults
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Oct 10 17:16:01 PDT 2002
>Originator:     Gabriel Finch
>Release:        unknown-1.0
gcc -v

Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux-gnu/3.2/specs
Configured with: ../configure --prefix=/usr --libdir=/usr/lib --with-slibdir=/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --enable-long-long --enable-__cxa_atexit --enable-languages=c,c++,ada,f77,objc,java --host=i586-mandrake-linux-gnu --with-system-zlib
Thread model: posix
gcc version 3.2 (Mandrake Linux 9.0 3.2-1mdk)
The following code causes a segfault on exit when compiled with gcc and run:

#include <stdio.h>

int main() {
  char *i,*s;
  sprintf(s,"%s","a");   // any format string works here
  sprintf(i,"xx%s",s);  // must be 2 or more chars before %s
  return 0;
Compile above code with gcc and execute it.


More information about the Gcc-bugs mailing list