From owner-freebsd-hackers Thu Aug 20 14:56:37 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id OAA03545 for freebsd-hackers-outgoing; Thu, 20 Aug 1998 14:56:37 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from whistle.com (s205m131.whistle.com [207.76.205.131]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id OAA03522 for ; Thu, 20 Aug 1998 14:56:25 -0700 (PDT) (envelope-from archie@whistle.com) Received: (from smap@localhost) by whistle.com (8.7.5/8.6.12) id OAA00262; Thu, 20 Aug 1998 14:55:43 -0700 (PDT) Received: from bubba.whistle.com(207.76.205.7) by whistle.com via smap (V1.3) id sma000258; Thu Aug 20 14:55:39 1998 Received: (from archie@localhost) by bubba.whistle.com (8.8.7/8.6.12) id OAA09132; Thu, 20 Aug 1998 14:55:39 -0700 (PDT) From: Archie Cobbs Message-Id: <199808202155.OAA09132@bubba.whistle.com> Subject: Re: Realloc fix for review In-Reply-To: <19980820202234.27107@follo.net> from Eivind Eklund at "Aug 20, 98 08:22:34 pm" To: eivind@yes.no (Eivind Eklund) Date: Thu, 20 Aug 1998 14:55:39 -0700 (PDT) Cc: imp@village.org, hackers@FreeBSD.ORG X-Mailer: ELM [version 2.4ME+ PL38 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Eivind Eklund writes: > > Recently, OpenBSD went through their source tree and fixed all > > instances of > > a = realloc(a, size); > > with > > na = realloc(a, size); > > if (!na) > > free(a); > > a = na; > > This change seems pointless. If the programmer is that thoughtless, > I'd believe he assume a to be valid later, too, and thus will > core-dump pretty soon. If other changes are done in the vicinity, > fine, but replacing the bogus code with a more well-thought-out > function means that we loose the indicator that the area is bogus. > IMO, bad to do without also loosing the bogosity. > > Apart from that, your solution was a nice solution to what I believe > to be the wrong problem :-) I think Warner's idea makes perfect sense.. if the semantics of "a" in the program are "pointer to valid data, or null if there was no memory for it". If the program already has bugs, then that's a separate issue. In other words, Warner's idea makes the total number of bugs not increase :-) I would bet that the majority of times when you see this: a = realloc(a, size); it's actually a bug in the program -- ie, assuming realloc() isn't going to return null. A better thing would be to replace all instances of "a = realloc(a, size)" with , depending on what the program is trying to do in that particular instance. -Archie ___________________________________________________________________________ Archie Cobbs * Whistle Communications, Inc. * http://www.whistle.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message