Date: Mon, 7 Jun 1999 01:15:54 -0500 From: Dan Nelson <dnelson@emsphone.com> To: Bryce Newall <data@dreamhaven.net> Cc: FreeBSD Questions List <freebsd-questions@FreeBSD.ORG>, trv@dreamhaven.net Subject: Re: Possible C library bug? Message-ID: <19990607011554.A74753@dan.emsphone.com> In-Reply-To: <Pine.NEB.4.10.9906062301420.99176-100000@ds9.dreamhaven.net>; from "Bryce Newall" on Sun Jun 6 23:07:42 GMT 1999 References: <Pine.NEB.4.10.9906062301420.99176-100000@ds9.dreamhaven.net>
next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (Jun 06), Bryce Newall said: > Greetings! > > One of my users recently brought to my attention a possible bug in > either the FreeBSD C compilers (cc and gcc), or one of the libraries. > The bug has to do with attempting to close a file that was never > successfully opened. In other words, with a statement something > like: > > f = fopen("filename", "r"); > > If the fopen fails, for whatever reason, and f has a value of NULL, > then this statement: > > flose(f); > > will return a segmentation fault, instead of simply not doing anything. Passing a NULL to fclose() results in undefined behaviour, since fclose closes open filehandles, and NULL isn't. Under FreeBSD, this means "segfault". This is similar to passing NULL to strcpy(). From the fclose manpage: NOTES fclose() does not handle NULL arguments; they will result in a segmentation violation. This is intentional - it makes it easier to make sure programs written under FreeBSD are bug free. This behaviour is an implementation detail, and programs should not rely upon it. -Dan Nelson dnelson@emsphone.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19990607011554.A74753>