santosh <> writes:
> Richard wrote:
>
>> Richard Heathfield <> writes:
>>
>>> Julian said:
>>>
>>>> 'evening.
>>>>
>>>> I'm not new to C and have been programming in it since I was 8 but
>>>> here's a strange problem I've never seen before.
>>>>
>>>> When I compile a program from our C course with a windows compiler
>>>> there is no problem but when I try to compile it with a linux
>>>> compiler it complains that
>>>>
>>>> a_03.c
.text+0x4d): warning: the `gets' function is dangerous
>>>> and should not be used.
>>>>
>>>> Is linux more dangerous than windows?
>>>
>>> No. Your Linux compiler warned you about a dangerous function that
>>> should never be used.
>>
>> Total and utter nonsense. C is used all over the place for creating
>> elements which are under strict control and the
>> program/process/function has a totally controlled and defined input
>> stream. In those scenarios gets is used flawlessly in millions of
>> programs around the world.
>>
>> if you can NOT define the input then I would agree. But in the real
>> world the input is indeed guarenteed in a properly functioning
>> system. if the system isn't well defined then all "bets are off" since
>> you can pretty much be sure that undefined behaviour/input has already
>> compromised the process pipeline.
>
> I wonder, can you give examples of sources of perfectly controlled and
> defined input? Certainly disk files can be tampered, as can pipes,
> sockets and almost every other device. Why risk it with gets when fgets
> is just as easy and safer?
If I have a well defined pipeline then any deviance make the entire line
corrupt.
If I have a process whose DEFINED input is say, 16 characters at a time
on its standard input then its not its job to ensure thats what
comes. Dont believe me? Try calling strcpy with NULL pointer as the
destination.
Since it has NO way of reporting back errors to the program feeding it,
what should me module do? Carry on processing this rogue data?
The point is this - one can worry all day long. Once can also be
practical and "real".
Its like the malloc business. If malloc fails for a few bytes the chance
of that program not exhibiting "Undefined Bahvaiour" because you checked
the return code is practically nil.