home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / os / linux / 22318 < prev    next >
Encoding:
Text File  |  1992-12-31  |  1.7 KB  |  41 lines

  1. Newsgroups: comp.os.linux
  2. Path: sparky!uunet!psinntp!sunic!news.funet.fi!hydra!klaava!wirzeniu
  3. From: wirzeniu@klaava.Helsinki.FI (Lars Wirzenius)
  4. Subject: Re: "the `gets' function is unreliable and should not be used"??!!!
  5. Message-ID: <1992Dec31.224410.6847@klaava.Helsinki.FI>
  6. Organization: University of Helsinki
  7. References: <C058sJ.Fuu@news.cso.uiuc.edu>
  8. Date: Thu, 31 Dec 1992 22:44:10 GMT
  9. Lines: 30
  10.  
  11. dld54032@uxa.cso.uiuc.edu (Dave Dribin) writes:
  12. >I am using SLS Linux v99.0.  Did I install anything wrong, or is the function
  13. >really unreliable.
  14.  
  15. You didn't install anything improperly (or at least this warning is
  16. not due to installation problems).  The fact is that gets is
  17. unreliable.  Period.
  18.  
  19. For an explanation of why gets is unreliable, read the comp.lang.c
  20. FAQ, or think about this: what happens if the input contains a line
  21. that is longer than the buffer you gave to gets?
  22.  
  23. If you can't find out the answer any other way, I'll be happy to mail
  24. it to those interested.  But the exercise is a healthy one, and
  25. teaches you something about designing good function interfaces.
  26.  
  27. > I would think that all the standard ASNI functions would be
  28. > reliable!
  29.  
  30. Hardly.  After you're done with gets, think about scanf("%s",buf).
  31. (Using sprintf, strcpy, and strcat without thinking properly can also
  32. cause unreliable problems, but gets and scanf are _inherently_
  33. unreliable, whereas the others are only dangerous if used improperly;
  34. a bit like a large enough mass of uranium is inherently unreliable,
  35. but a large mass of steel is dangerous only if dropped on somebody's
  36. head.)
  37.  
  38. --
  39. Lars.Wirzenius@helsinki.fi  (finger wirzeniu@klaava.helsinki.fi)
  40.    MS-DOS, you can't live with it, you can live without it.
  41.