*BSD News Article 18572


Return to BSD News archive

Path: sserve!newshost.anu.edu.au!munnari.oz.au!constellation!convex!convex!cs.utexas.edu!uunet!decwrl!decwrl!usenet.coe.montana.edu!bsd.coe.montana.edu!nate
From: nate@bsd.coe.montana.edu (Nate Williams)
Newsgroups: comp.os.386bsd.questions
Subject: Re: Using gets() [ Was Re: nn ]
Date: 18 Jul 1993 10:16:04 GMT
Organization: Montana State University
Lines: 26
Message-ID: <22b7t4$78p@pdq.coe.montana.edu>
References: <226q88INN56k@xs4all.hacktic.nl> <1993Jul17.203914.25267@fwi.uva.nl> <229qig$53k@pdq.coe.montana.edu> <OLEG.93Jul17185604@gd.cs.csufresno.edu>
NNTP-Posting-Host: bsd.coe.montana.edu

In article <OLEG.93Jul17185604@gd.cs.csufresno.edu> oleg@gd.cs.CSUFresno.EDU (Oleg Kibirev) writes:
>In article <229qig$53k@pdq.coe.montana.edu> nate@bsd.coe.montana.edu (Nate Williams) writes:
>   "GETS() is inherently unsafe since it does not check to see if there is
>   enough room in the buffer"  

>Not to start another  religious war... There is nothing wrong with using  gets
>if  there is no good  reason  for input to be longer than some limit.  

If that's the case, why not just add a couple more characters to your program
just to be safe.

I mean, how much harder is it to type

fgets(buf, 8, stdin);
  instead of
gets(buf);

You get all the benefits at hardly any cost. :-)


Nate
-- 
nate@bsd.coe.montana.edu     |  In the middle of it ........ again. 
nate@cs.montana.edu          |  Running/supporting one of many freely available 
work #: (406) 994-4836       |  Operating Systems for [34]86 machines.
home #: (406) 586-0579       |  (based on Net/2, name changes all the time :-)