This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: fopen(NULL) causes segmentation fault
- To: "Andrew Wiseman" <a dot wiseman at bandc dot dircon dot co dot uk>
- Subject: Re: fopen(NULL) causes segmentation fault
- From: dvv at dvv dot ru (Dima Volodin)
- Date: Tue, 28 Mar 2000 20:27:12 GMT
- Cc: <gcc-bugs at gcc dot gnu dot org>
- Organization: Huh?
- References: <NBBBLEHDEKMCNNANFHAKCEGFDHAA.a.wiseman@bandc.dircon.co.uk>
On Tue, 28 Mar 2000 19:02:20 +0100, you wrote:
>main()
>{
> long *file_rep = 0x0;
> fclose(file_rep);
>}
>
>Anyway, I
>don't believe it should cause a segmentation fault. I have used the same
>(buggy!) code on many different machines (Suns, PowerPC machines and others)
>running a variety of operating systems (AIX, Solaris 1 & 2, SCO and others)
>with a number of different compilers, and not one has ever given me a
>segmentation fault in this way.
It's not the compiler that gives you the segmentation fault, it's your
program that goes down. You try to use a non-existent data address and
the OS is absolutely right in terminating your process at this moment.
More of that - you got lucky with Linux as it's quickly showed you that
you cannot get away with things like that. It's too bad that, say, in
Solaris, it doesn't happen this way even if gcc is used to compile this
piece of code.
BTW, NULL is _not_ long*.
>Andrew Wiseman
>Software Production Manager
Dima