On Fri, Jan 16, 2009 at 2:21 AM, Christoph Mallon
<[email protected]> wrote:
> 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().

    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;

}

[gcoo...@optimus ~]$ gcc -o badfile badfile.c
[gcoo...@optimus ~]$ ./badfile
Errno: 2
Segmentation fault: 11 (core dumped)
[gcoo...@optimus ~]$
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[email protected]"

Reply via email to