gets(3) nonsense

Paul J. Mech pmech at oucsace.cs.OHIOU.EDU
Thu Nov 17 19:27:47 AEST 1988


In article <2747 at hound.UUCP>, rkl1 at hound.UUCP (K.LAUX) writes:
> 
> 	Well, I suppose that if gets () is capable of overflowing the buffer,
> the way to go would be to read the input one character at a time and check
> for buffer overflow oneself.  It would be trivial to write a function to do
> this, and you only have to do it once and use it from then on instead of gets ()
> 
> --rkl

Agreed, it was one of the first functions I wrote (I called mine getln()).
I just don't see why some people are damning gets(). I still use gets()
whenever I am writing a quick and dirty program that I will swiftly (read
immediately) discard after use, or for some aid that only I will have
access to with all the data being known not to cause an overflow. If a
customer is to get within spitting distance of it, or if I pass it on to
another programmer, I use getln(), and include the (rather trivial) source.
Despite what seems to be the hysteria of the moment, gets() is useful. But
like most things associated with 'C', you have to be careful how you use
it.

pjm



More information about the Comp.lang.c mailing list