home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!pipex!bnr.co.uk!uknet!mcsun!news.funet.fi!funic!nntp.hut.fi!nntp!Pauli.Ramo
- From: Pauli.Ramo@hut.fi (no, I don't repeat it!)
- Newsgroups: comp.os.linux
- Subject: Re: "the `gets' function is unreliable and should not be used"??!!!
- Message-ID: <PAULI.RAMO.93Jan1003725@vipunen.hut.fi>
- Date: 1 Jan 93 00:37:25 GMT
- References: <C058sJ.Fuu@news.cso.uiuc.edu>
- Sender: usenet@nntp.hut.fi (Usenet pseudouser id)
- Reply-To: Pauli.Ramo@hut.fi
- Organization: /u/opi/s/ramo/.organization
- Lines: 25
- In-Reply-To: dld54032@uxa.cso.uiuc.edu's message of Thu, 31 Dec 1992 21:53:06 GMT
- Nntp-Posting-Host: vipunen.hut.fi
-
- 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
- --
- Disclaimer fault - lawyers dumped
-