This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
fopen(NULL) causes segmentation fault
- TO: <gcc-bugs at gcc dot gnu dot org>
- Subject: fopen(NULL) causes segmentation fault
- From: "Andrew Wiseman" <a dot wiseman at bandc dot dircon dot co dot uk>
- Date: Tue, 28 Mar 2000 19:02:20 +0100
VERSION
=======
This is 2.95.2 compiled for a Pentium
for Mandrake Linux 7.0 (Kernel 2.2.14-15mdk)
gcc -v reports:
Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/specs
gcc version 2.95.2 19991024 (release)
But this same "bug" can be found in
1. gcc version 2.7.2.1 under RedHat 5.2 (Kernel 2.0.36)
2. gcc version 2.7.2.3 under Corel Linux 1.0 (Kernel 2.2.12)
But it does NOT appear in
gcc version 2.7.0 under SunSoft Interactive Unix 4.1a (i/c maintenance
release)
SOURCE TO REPRODUCE BEHAVIOUR (also attached)
=============================
main()
{
long *file_rep = 0x0;
fclose(file_rep);
}
BEHAVIOUR
=========
When you compile the source above and run it...
gcc gcc2.c
./a.out
You get...
Segmentation fault
Now you might say that fclose(NULL) is a bit of a silly thing to do. (And in
the real world program that led me to discover this problem, file_rep above
was not supposed to be NULL but was due to a bug in my code.) 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.
MACHINE DETAILS
===============
A PC containing a Cyrix running at 133 MHz (equivalent to a Pentium 166,
apparently).
Operating System: Mandrake Linux 7.0 (Kernel 2.2.14-15mdk)
Compiler was installed as is from the CDROM.
As mentioned above, this also occurs in other versions of GCC with other
versions of Linux.
--
Andrew Wiseman
Software Production Manager
BENSASSON & CHALMERS LIMITED
gcc2.c