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

strange SIGSEV


The following code seems to produce SIGSEV only on amd64 platforms (both on
GNU/Linux and on GNU/kFreeBSD).  Anyone has an idea what is the portability
problem here?

Perhaps that buf is deallocated inmediately after getfoo() returns?  I could
switch to strdup()/free() but I'd like to figure out what's going on first.

$ cat buffer.c
#include <string.h>
char *
        static char buf[128];
        strcpy (buf, "foo");
        return buf;
$ cat test.c
#include <stdio.h>
#include <sys/param.h>
#include <sys/stat.h>

main ()
  printf ("%s\n", getfoo ());
$ gcc -fPIC buffer.c -shared -o buffer.so && gcc test.c -o test ./buffer.so && ./test
Segmentation fault
$ gcc -fPIC -c buffer.c && gcc test.c -o test buffer.o && ./test

Note: this currently breaks swap{on,off,ctl} on kfreebsd-amd64

Robert Millan

Reply to: