home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / os / linux / 22319 < prev    next >
Encoding:
Internet Message Format  |  1992-12-31  |  1.6 KB

  1. Path: sparky!uunet!pipex!bnr.co.uk!uknet!mcsun!news.funet.fi!funic!nntp.hut.fi!nntp!Pauli.Ramo
  2. From: Pauli.Ramo@hut.fi (no, I don't repeat it!)
  3. Newsgroups: comp.os.linux
  4. Subject: Re: "the `gets' function is unreliable and should not be used"??!!!
  5. Message-ID: <PAULI.RAMO.93Jan1003725@vipunen.hut.fi>
  6. Date: 1 Jan 93 00:37:25 GMT
  7. References: <C058sJ.Fuu@news.cso.uiuc.edu>
  8. Sender: usenet@nntp.hut.fi (Usenet pseudouser id)
  9. Reply-To: Pauli.Ramo@hut.fi
  10. Organization: /u/opi/s/ramo/.organization
  11. Lines: 25
  12. In-Reply-To: dld54032@uxa.cso.uiuc.edu's message of Thu, 31 Dec 1992 21:53:06 GMT
  13. Nntp-Posting-Host: vipunen.hut.fi
  14.  
  15. In article <C058sJ.Fuu@news.cso.uiuc.edu> dld54032@uxa.cso.uiuc.edu (Dave Dribin) writes:
  16.  
  17. [about the reliability of gets()]
  18.  
  19. >I am using SLS Linux v99.0.  Did I install anything wrong, or is the function
  20. >really unreliable.  I would think that all the standard ASNI functions would
  21. >be reliable!  Thanx in andvance, and happy new year...
  22.  
  23. The problem with gets() is that you can't pass the length of your string
  24. buffer to it. If, for example, you reserved 1000 bytes and the program
  25. got an input line of 2000 bytes, gets() could write the rest of the data
  26. (after the first 1000 bytes) to whatever area of memory there is after
  27. your buffer. If you are lucky, you just get SIGSEGV, if not, you can
  28. screw up much other variables.
  29.  
  30. This problem does not exist with fgets(), because one of it's parameters
  31. is the maximum amount of data read (=buffer length in most cases). So, you
  32. could replace the gets(str) with fgets(str,256,stdin), if your buffer is
  33. 256 bytes long.
  34.  
  35. Happy new year!
  36.  
  37.     Pauli
  38. --
  39. Disclaimer fault - lawyers dumped
  40.