Date: Tue, 29 Sep 1998 16:14:51 +0400 From: Dmitrij Tejblum <tejblum@arc.hq.cti.ru> To: Bruce Evans <bde@zeta.org.au> Cc: dg@root.com, shmit@kublai.com, wb@yorikke.arb-phys.uni-dortmund.de, freebsd-bugs@FreeBSD.ORG Subject: Re: bin/7742: fclose(3) dumps core on NULL Message-ID: <199809291214.QAA23755@arc.hq.cti.ru> In-Reply-To: Your message of "Tue, 29 Sep 1998 09:47:01 %2B1000." <199809282347.JAA18084@godzilla.zeta.org.au>
next in thread | previous in thread | raw e-mail | index | archive | help
Bruce Evans wrote: > >Why is free(NULL) permissable, but not fclose(NULL)? > > Because the C standard says so. Well, a program calling fclose(NULL) is non-conforming. And what? A lot of non-conforming programs work on FreeBSD. Anyhow, the behavior of printf("%s", (char*)NULL) is not defined by the standard too, but on FreeBSD this print "(null)" rather than dumps core. IMO, this is far more bogus, and I'd rather remove this feature. Anyway, fclose(NULL) is not like strlen(NULL) or fprintf(NULL, ...). fclose(NULL) is like free(NULL), and I claim that it is in the spirit of C if fclose(NULL) permitted :-| :-|. (It is definitely in the spirit of C++, and the standard C library is a part of the standard C++ library.) Note that FreeBSD is apparently the only modern Unix that doesn't permit fclose(NULL), thus the programmer doesn't need to "know about this problem": fixing his code doesn't buy him portability to anything else. This "problem" is FreeBSD-specific in practice, and we should remove it as such. (*) Also, it is irrelevant that programmers don't test result of fclose(NULL). fclose(NULL) simple should not be considered as a bug, just like free(NULL). Appendix. OS comparison. FreeBSD Linux Solaris OSF/1 N/A 2.5 3.0 fclose(NULL) core work work work fprintf(NULL, "Hi") core work core core printf("%s", (char*)NULL) work work core work IMO, Solaris' behavior is (most) correct. Dima (*) Apparently, most (or all) Windows compilers do not permit fclose(NULL). It is totally irrelevant, though. :-) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199809291214.QAA23755>