Re: [Lit.] Buffer overruns
From: Phil Carmody (thefatphil_demunge_at_yahoo.co.uk)
Date: 02/14/05
- Next message: David Kastrup: "Re: Surrogate factoring, state of the art"
- Previous message: BRG: "Re: Thou shalt have no other gods before the ANSI C standard"
- In reply to: Dave Thompson: "Re: [Lit.] Buffer overruns"
- Next in thread: Randy Howard: "Re: [Lit.] Buffer overruns"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Mon, 14 Feb 2005 14:12:25 +0200
On Mon, 14 Feb 2005 09:46:14 +0000, Dave Thompson wrote:
>> #define gets(x) fgets(x,sizeof(x),stdin)
>>
>> Two wrongs make a right! <g,d&r, pursued by nasal demons>
Is that a sign of nuddsdefined behaviour?
(A.F.C.Q - are usenet personalities, such as ArchiePu, considered
"computer folklore"?)
> Just in case anyone has the intestinal fortitude and colossal silliness
> to look for programming advice this deep in this thread:
>
> that isn't an exact replacement; fgets does not trim the newline '\n'
> character from a completely read line as gets does. This is (hidden)
> in FAQ 7.1 for comp.lang.c at the usual places and
> http://www.eskimo.com/~scs/C-faq/top.html
It's not even a sensible replacement. If you give it a pointer, rather
than an array, then the sizeof is almost certainly not what you want.
It also evaluates, in unspecified order, x twice, so nonsense like
gets(*(pp++)) breaks.
Phil
- Next message: David Kastrup: "Re: Surrogate factoring, state of the art"
- Previous message: BRG: "Re: Thou shalt have no other gods before the ANSI C standard"
- In reply to: Dave Thompson: "Re: [Lit.] Buffer overruns"
- Next in thread: Randy Howard: "Re: [Lit.] Buffer overruns"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]