bug-glibc
[Top][All Lists]
Advanced

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

Re: fclose bug?


From: Wolfram Gloger
Subject: Re: fclose bug?
Date: Sun, 3 Mar 2002 13:02:42 +0100 ("MET)

> This testcase segfaults with the Red Hat glibc-2.2.4-19.3 rpm.  AFAICT, the
> second fclose should detect the error and return EOF rather than crashing.
> 
>   #include <stdio.h>
> 
>   int main ()
>   {
>     FILE *fp = fopen ("/dev/null", "r");
>     fclose (fp);
>     fclose (fp);
>   }

Like Ulrich said, this is undefined behaviour.  Single Unix and the
Linux man page has specific wording to this effect:

http://www.rdg.opengroup.org:80/onlinepubs/007908799/xsh/fclose.html

Even something like

        fclose(fp);
        if (fp != NULL) /* bug! */
           ...

would be undefined behaviour.  Unfortunately, AFAICS, C9x is _lacking_
specific wording to this effect (but of course it nowhere defines use
of a stream after an fclose() either).

Regards,
Wolfram.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]