Re: Confused by segfault with legitimate call to strerror(3) on amd64 / sysctl (3) setting `odd' errno's



Christian Kandeler schrieb:
On Friday 16 January 2009 09:53, Christoph Mallon wrote:

int
main() {

int mib[4];

size_t len;

if (sysctlnametomib("kern.ipc.shmmax", mib, &len) != 0) {
printf("Errno: %d\n", errno);
errx(errno, "Error: %s", strerror(errno));
The use of errno is wrong. printf might change errno.

I don't think printf() can set errno. And even if it could, it

Of course it can. See ISO/IEC 9899:1999 (E) §7.5:3.

wouldn't matter, because C has call-by-value semantics.

This has nothing to do with call-by-value. errno is read (even twice!) *after* the call to printf().
_______________________________________________
freebsd-hackers@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: detabbing again
    ... Calling printf can loose the value of errno. ... test argvto see if it is zero and spit this case back to the user ... it is your wording of what I said then it doesn't matter -- I don't ...
    (comp.lang.c)
  • Re: detabbing again
    ... Calling printf can loose the value of errno. ... test argvto see if it is zero and spit this case back to the user ... to the pointer whose address you pass to strtol. ...
    (comp.lang.c)
  • Re: trim whitespace
    ... since strerror (errno) is evaluated before printf is called. ... way more sense to set errno and return a failure indication. ... The only diagnostic a library function should emit is the result of an assert! ...
    (comp.lang.c)
  • Re: detabbing again
    ... argv1 is 5 ... errno is 0 ... printf(" errno is %d\n", errno); ... naturals, then only zero reverses the outcome, given m. ...
    (comp.lang.c)
  • Re: strtoul() behavior
    ... errno is used in a different way: ... to 0 and calling strtoulthat could set errno to a non-zero value. ... (There's a printf, but it's followed by a "return -1".) ... (blah blah, printf vs. debugginer, blah blah) ...
    (comp.lang.c)