From: no, I don't repeat it! (Pauli.Ramo@hut.fi)
Date: 12/31/92


From: Pauli.Ramo@hut.fi (no, I don't repeat it!)
Subject: Re: "the `gets' function is unreliable and should not be used"??!!!
Date: 1 Jan 1993 00:37:25 GMT

In article <C058sJ.Fuu@news.cso.uiuc.edu> dld54032@uxa.cso.uiuc.edu (Dave Dribin) writes:

[about the reliability of gets()]

>I am using SLS Linux v99.0. Did I install anything wrong, or is the function
>really unreliable. I would think that all the standard ASNI functions would
>be reliable! Thanx in andvance, and happy new year...

The problem with gets() is that you can't pass the length of your string
buffer to it. If, for example, you reserved 1000 bytes and the program
got an input line of 2000 bytes, gets() could write the rest of the data
(after the first 1000 bytes) to whatever area of memory there is after
your buffer. If you are lucky, you just get SIGSEGV, if not, you can
screw up much other variables.

This problem does not exist with fgets(), because one of it's parameters
is the maximum amount of data read (=buffer length in most cases). So, you
could replace the gets(str) with fgets(str,256,stdin), if your buffer is
256 bytes long.

Happy new year!

        Pauli