strange SIGSEV
Hi!
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 *
getfoo()
{
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
foo
Note: this currently breaks swap{on,off,ctl} on kfreebsd-amd64
--
Robert Millan
Reply to: