Subject: Re: Possible bug relating to malloc()/realloc(), popen(), and read()
To: Vincent Stemen <netbsd@crel.us>
From: Michael Graff <explorer@flame.org>
List: port-i386
Date: 12/08/2004 11:41:38
On Thursday 02 December 2004 12:58, Vincent Stemen wrote:
> On Thu, Dec 02, 2004 at 03:25:35PM +0100, Martin Husemann wrote:
> > On Wed, Dec 01, 2004 at 07:05:40PM -0600, Vincent Stemen wrote:
> > > but the pointer I get back from realloc() does
> > > not point to the beginning of the data allocated by the first malloc()
> > > as it should.
> >
> > Why do you think it should?
>
> Because the manual on realloc() says it should and it would not be
> very useful otherwise. Either way, as pointed out by other replies, I
> was misinterpreting the result. That was not the problem.
My read of the manual:
The realloc() function changes the size of the previously allocated mem-
ory referenced by ptr to size bytes and returns a pointer to the (possi-
bly moved) object. The contents of the memory are unchanged up to the
Note the "possibly moved" part.
realloc() does not guarantee that the new pointer is the same as the old, only
that the contents were copied if it was moved.
--Michael