Re: Malcolm's new book - Chapter 1 review
- From: Richard <rgrdev@xxxxxxxxx>
- Date: Sun, 02 Sep 2007 19:34:56 +0200
Kelsey Bjarnason <kbjarnason@xxxxxxxxx> writes:
[snips]inF>
On Wed, 29 Aug 2007 19:24:19 +0100, Malcolm McLean wrote:
In practise fgets() is too hard for the average programmer to use correctly,
as has time after time been demonstrated here. I caused outrage by
suggesting that most programs would be safer if they replaced fgets() with
gets(). However I was right.
The only one here I can recall ever claiming to use gets safely was (from
memory) Dann Pop. However, that was (again, from memory) in a rather
limited set of circumstances.
The use of gets is *never* warranted except, possibly, in very rare cases
where you absolutely control all possible inputs, as without that, the
function simply cannot be used safely.
It is a function to be used only by experts, and only in very unusual
cases; I can't see any way you could have recommended it and not been
simply wrong.
Would I recommend it? Not really/necessarily, but a lot code is written where
the input limits are set by the run time setup. It seems to be favorite
icon for people wanting to demonstrate their knowledge of buffer over runs.
The real answer is not to use gets() but something like ggets()
Which, presumably, can be used safely. Or just learn how to use
fgets.
ggets() is a mess. It does nothing particularly well - its increment is
poorly thought out, is non configurable and has no idea of how to bail
out. It is a far better idea to use fgets() and do it properly.
.
- Follow-Ups:
- Re: Malcolm's new book - Chapter 1 review
- From: Kelsey Bjarnason
- Re: Malcolm's new book - Chapter 1 review
- From: Richard
- Re: Malcolm's new book - Chapter 1 review
- References:
- Re: Malcolm's new book - Chapter 1 review
- From: Kelsey Bjarnason
- Re: Malcolm's new book - Chapter 1 review
- Prev by Date: Re: size_t problems
- Next by Date: Re: Access violation in free()
- Previous by thread: Re: Malcolm's new book - Chapter 1 review
- Next by thread: Re: Malcolm's new book - Chapter 1 review
- Index(es):
Relevant Pages
|