Subject: Re: Possible bug relating to malloc()/realloc(), popen(), and read()
To: Vincent Stemen <netbsd@crel.us>
From: James Chacon <jmc@NetBSD.org>
List: port-i386
Date: 12/02/2004 15:55:37
On Thu, Dec 02, 2004 at 12:58:41PM -0600, 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.
> 
> 
> > Your program does not properly handle return values from read(). You need
> > to check -1 and errno == EAGAIN at least, if you don't read from straight
> > disk files.
> > 
> > Martin
> 
> It does check for -1.  According to the manual, EAGAIN is only for
> non-blocking I/O which I did not think applied in this case.

Actually I beleive you can get it on an interruption as well (say attaching
with the debugger). I don't recall if read does an automatic restart when
getting a signal or just returns EAGAIN.

James