This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: fopen(NULL) causes segmentation fault


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]