From owner-freebsd-bugs Tue Sep 29 05:16:48 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id FAA10547 for freebsd-bugs-outgoing; Tue, 29 Sep 1998 05:16:48 -0700 (PDT) (envelope-from owner-freebsd-bugs@FreeBSD.ORG) Received: from arc.hq.cti.ru (arc.hq.cti.ru [195.34.40.3]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id FAA10542 for ; Tue, 29 Sep 1998 05:16:42 -0700 (PDT) (envelope-from tejblum@arc.hq.cti.ru) Received: from arc.hq.cti.ru (localhost [127.0.0.1]) by arc.hq.cti.ru (8.9.0/8.9.0) with ESMTP id QAA23755; Tue, 29 Sep 1998 16:14:52 +0400 (MSD) Message-Id: <199809291214.QAA23755@arc.hq.cti.ru> X-Mailer: exmh version 2.0zeta 7/24/97 To: Bruce Evans 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 In-reply-to: Your message of "Tue, 29 Sep 1998 09:47:01 +1000." <199809282347.JAA18084@godzilla.zeta.org.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Tue, 29 Sep 1998 16:14:51 +0400 From: Dmitrij Tejblum Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org 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