Re: adapting getline
- From: Ben Bacarisse <ben.usenet@xxxxxxxxx>
- Date: Mon, 20 Apr 2009 16:52:45 +0100
Richard <rgrdev_@xxxxxxxxx> writes:
James Kuyper <jameskuyper@xxxxxxxxxxx> writes:
kid joe wrote:
On Mon, 20 Apr 2009 02:10:23 +0100, Ben Bacarisse wrote:
Franken Sense <frank@xxxxxxxxxxxxxxx> writes:
buf = realloc(buf, ++bufsz);This only works if realloc never fails.
Hi Ben,
In practise realloc never fails in this situation as the amount of memory
involved is very small. Even if it does fail, then the next line
*(buf + bufsz - 1) = c;
will detect the error automatically and exit the program with an error
message, so there's no danger of data corruption.
No, such code is NOT guaranteed to detect the error automatically. The
behavior is undefined. There is a popular notion that "undefined
behavior" means that your program will exit immediately. That is a
I suspect he means on his system.
His code won't work, reliably, on many systems. For some reason he
picked only one comment to talk about. The code is wrong for reasons
other than just the realloc assumption.
--
Ben.
.
- References:
- adapting getline
- From: Franken Sense
- Re: adapting getline
- From: kid joe
- Re: adapting getline
- From: Franken Sense
- Re: adapting getline
- From: kid joe
- Re: adapting getline
- From: Franken Sense
- Re: adapting getline
- From: Ben Bacarisse
- Re: adapting getline
- From: kid joe
- Re: adapting getline
- From: James Kuyper
- Re: adapting getline
- From: Richard
- adapting getline
- Prev by Date: Re: Value of Un-initialized Stack Variable in OSX
- Next by Date: Re: A doubly linked-list in C
- Previous by thread: Re: adapting getline
- Next by thread: Re: adapting getline
- Index(es):
Relevant Pages
|