From owner-freebsd-stable Tue Oct 16 14:59:39 2001 Delivered-To: freebsd-stable@freebsd.org Received: from freeway.dcfinc.com (cx74889-a.phnx3.az.home.com [24.1.193.157]) by hub.freebsd.org (Postfix) with ESMTP id D8BA337B407 for ; Tue, 16 Oct 2001 14:59:35 -0700 (PDT) Received: (from chad@localhost) by freeway.dcfinc.com (8.8.8/8.8.8) id OAA23603; Tue, 16 Oct 2001 14:59:09 -0700 (MST) (envelope-from chad) Date: Tue, 16 Oct 2001 14:59:09 -0700 From: "Chad R. Larson" To: Dimitry Andric Cc: Nate Williams , freebsd-stable@FreeBSD.ORG Subject: Re: setenv() cores with NULL value [was Re: Gdm proplem on 4.4] Message-ID: <20011016145909.B23454@freeway.dcfinc.com> References: <200110160353.f9G3rO728525@harmony.village.org> <20011016013834.E293@blossom.cjclark.org> <200110161002.f9GA2CA08544@shalimar.net.au> <15308.25432.608079.646993@nomad.yogotech.com> <441356059.20011016201751@xs4all.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <441356059.20011016201751@xs4all.nl>; from dim@xs4all.nl on Tue, Oct 16, 2001 at 08:17:51PM +0200 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 On Tue, Oct 16, 2001 at 08:17:51PM +0200, Dimitry Andric wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On 2001-10-16 at 18:42:00 Nate Williams wrote: > > NW> printf("%s", ""); > NW> printf("%s", NULL); > > NW> The first will work, the second will dump core. > > Nope, it will print the string "(null)", as you can see in > /usr/src/lib/libc/stdio/vfprintf.c, around line 673: > > case 's': > if ((cp = GETARG(char *)) == NULL) > cp = "(null)"; > > Almost any printf I've ever seen does the same. Yes, but that is a function of printf(3), not of dereferencing NULL pointers. Modify slightly: /* dereference a null pointer */ #define NULL 0 main() { char *foo; static int bar; foo = "junk"; bar = *foo; foo = NULL; bar = *foo; } -crl -- Chad R. Larson (CRL15) 602-953-1392 Brother, can you paradigm? chad@dcfinc.com chad@larsons.org larson1@home.com DCF, Inc. - 14623 North 49th Place, Scottsdale, Arizona 85254-2207 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-stable" in the body of the message