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