Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Aug 1998 14:55:39 -0700 (PDT)
From:      Archie Cobbs <archie@whistle.com>
To:        eivind@yes.no (Eivind Eklund)
Cc:        imp@village.org, hackers@FreeBSD.ORG
Subject:   Re: Realloc fix for review
Message-ID:  <199808202155.OAA09132@bubba.whistle.com>
In-Reply-To: <19980820202234.27107@follo.net> from Eivind Eklund at "Aug 20, 98 08:22:34 pm"

next in thread | previous in thread | raw e-mail | index | archive | help
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 <insert bug-free code here>, 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199808202155.OAA09132>