Confused by segfault with legitimate call to strerror(3) on
amd64 / sysctl (3) setting `odd' errno's
Christoph Mallon
christoph.mallon at gmx.de
Fri Jan 16 02:48:17 PST 2009
Garrett Cooper schrieb:
> Ok, I just installworld'ed, recompiled the program with the
> following modifications, and I still get segfaults. And the question
> of the night is: why amd64 on a VERY recent CURRENT?
> I'm going to try the same app on an amd64 freebsd VMware instance
> with RELENG_7.
> Remember: just because a bunch of other people aren't reporting
> issues with CURRENT/amd64 doesn't mean that it isn't environmental,
> related to my hardware or compile options ;).
> Cheers,
> -Garrett
>
> #include <errno.h>
> #include <stdio.h>
> #include <sys/stat.h>
>
> int
> main()
> {
>
> struct stat sb;
>
> int o_errno;
>
> if (stat("/some/file/that/doesn't/exist", &sb) != 0) {
> o_errno = errno;
> printf("Errno: %d\n", errno);
> printf("%s\n", strerror(o_errno));
> }
>
> return 0;
>
> }
>
> #include <errno.h>
> #include <stdio.h>
> #include <sys/stat.h>
>
> int
> main()
> {
>
> struct stat sb;
>
> int o_errno;
>
> if (stat("/some/file/that/doesn't/exist", &sb) != 0) {
> o_errno = errno;
> printf("Errno: %d\n", errno);
> printf("%s\n", strerror(o_errno));
> }
>
> return 0;
>
> }
>
> [gcooper at optimus ~]$ gcc -o badfile badfile.c
> [gcooper at optimus ~]$ ./badfile
> Errno: 2
> Segmentation fault: 11 (core dumped)
> [gcooper at optimus ~]$
Well, compile with -g, start in gdb, check what value is wrong, the
usual stuff. Probably the return value of strerror() is interesting.
More information about the freebsd-hackers
mailing list