From owner-freebsd-stable Tue Oct 16 20:40:21 2001 Delivered-To: freebsd-stable@freebsd.org Received: from mx1.gbch.net (gw.gbch.net [203.24.22.66]) by hub.freebsd.org (Postfix) with SMTP id 902EB37B405 for ; Tue, 16 Oct 2001 20:40:14 -0700 (PDT) Received: (qmail 25210 invoked by uid 1001); 17 Oct 2001 13:40:13 +1000 Message-ID: X-Posted-By: GJB-Post 2.21 16-Jun-2001 X-Operating-System: FreeBSD 4.2-RELEASE i386 X-Location: Brisbane, Australia; 27.49841S 152.98439E X-URL: http://www.gbch.net/gjb.html X-Image-URL: http://www.gbch.net/gjb/gjb-auug048.gif X-GPG-Fingerprint: EBB2 2A92 A79D 1533 AC00 3C46 5D83 B6FB 4B04 B7D6 X-PGP-Public-Keys: http://www.gbch.net/keys.html Date: Wed, 17 Oct 2001 13:40:13 +1000 From: Greg Black To: nate@yogotech.com (Nate Williams) Cc: Zero Sum , cjclark@alum.mit.edu, "Crist J. Clark" , Heath Nielson , Warner Losh , David Marker , freebsd-stable@FreeBSD.ORG Subject: Re: setenv() cores with NULL value [was Re: Gdm proplem on 4.4] References: <200110160353.f9G3rO728525@harmony.village.org> <20011016013834.E293@blossom.cjclark.org> <200110161002.f9GA2CA08544@shalimar.net.au> <15308.25432.608079.646993@nomad.yogotech.com> In-reply-to: <15308.25432.608079.646993@nomad.yogotech.com> of Tue, 16 Oct 2001 10:42:00 CST Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-freebsd-stable@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Nate Williams wrote: | > > > setenv("TEST1", "", 1); | > > > setenv("TEST2", NULL, 1); | > > | > > A huge difference. In the first case, the second argument is a | > > pointer aimed at a string which contains the bytes, '\0'. In the | > > second case, we have a null pointer. Null pointers point at nothing. | > | > I had that out with a compiler manufacturer long, long ago. At that | > time it was a requirement for a 'correct' C compiler to regard a null | > pointer and a pointer to a null string as sematically equivalent. | | As others have pointed out, this was never the case. | | Here's a great example of why they aren't the same thing. | | printf("%s", ""); | printf("%s", NULL); | | The first will work, the second will dump core. The second has never | worked, and should never work. Well, it has often "worked"; but it has always been wrong. The world would have been better off if people had not fudged things in past operating systems to make this incorrect code appear to work. And I think that all those printf() library functions that print "(null)" instead of allowing a core dump are doing the wrong thing too. It's wrong, so don't do it. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-stable" in the body of the message