Path: utzoo!attcan!uunet!seismo!sundc!pitstop!sun!decwrl!labrea!csli!gandalf From: gandalf@csli.STANFORD.EDU (Juergen Wagner) Newsgroups: comp.sources.d Subject: Re: v05i053: A "safe" replacement for gets() Message-ID: <6508@csli.STANFORD.EDU> Date: 20 Nov 88 06:19:24 GMT Reply-To: wagner@arisia.xerox.com (Juergen Wagner) Organization: Center for the Study of Language and Information, Stanford U. Lines: 37 I am wondering how long the discussion will last... The alternatives were: o Nuke gets() this will break the standard and a number of programs. o Don't use gets() Probably the best suggestion. Everybody who doesn't like gets, should just stop using it. o # define gets(s) fgets(...) sizeof returns sizeof(char *) if the buffer is not an array. That will cause unexpected effects. :-) o replace gets by something more intelligent We arrive at fgets. The "more intelligent" will certainly mean some kind of overflow checking. That's already available in fgets. o leave everything as it is Well, this discussion reminds me of the "rm *" discussions which come up every four months or so. The result: umpteen plus one 'best' solutions to the problem. UNIX happens to provide very powerful tools, and nobody keeps the super-user from putting a /bin/rm -fr / into his/her .login but that's not the point: The question is: How do some people under some circumstances protect themselves against themselves? The answer is: It depends! Probably all of the above answers are optimal in some sense - in some situation where you exactly know the file format, gets is just what you want. In other cases, the #define allows a shorthand for the overflow checking version. In yet other cases you may need a wrapper complaining when the line is actually longer than you thought it would be. And so on.... All that is, of course, my personal opinion. make flame | mail wagner@arisia.xerox.com -- Juergen Wagner gandalf@csli.stanford.edu wagner@arisia.xerox.com