v05i053: A "safe" replacement for gets()

randy orrison randy at halcdc.UUCP
Thu Nov 17 03:26:27 AEST 1988


In article <674 at quintus.UUCP> Brandon Allbury writes:
|[Aaaaagh.  I always suspected gets() was a potential bomb.  How about
|
|#define gets(s) fgets(s, sizeof s, stdin)
|
|as a quick fix?  ++bsa]

{
	char *s;

	s = malloc (80);

	gets (s);
}

Two problems: the space after gets would kill it if it's a macro, and
sizeof (s) != 80 (on most machines).  Which means that you'd have to
examine your code to make sure the macro would work, and fix it if
not, so why not just fix it to use fgets?

	-randy
-- 
Randy Orrison - Control Data in the Hills of Arden	randy at halcdc.uucp
aka randy@{ux.acss.umn.edu, umnacvx.bitnet, cctb.mn.org, umn-cs.uucp}

ZQOTD:	"Make me look like LINDA RONSTADT again!!"



More information about the Comp.lang.c mailing list