Path: utzoo!attcan!uunet!husc6!cmcl2!nrl-cmf!mailrus!ncar!tank!nic.MR.NET!shamash!halcdc!randy From: randy@halcdc.UUCP (randy orrison) Newsgroups: comp.lang.c Subject: Re: v05i053: A "safe" replacement for gets() Summary: red face time Message-ID: <122@halcdc.UUCP> Date: 18 Nov 88 18:48:49 GMT References: <674@quintus.UUCP> <117@halcdc.UUCP> <468@auspex.UUCP> Reply-To: randy@halcdc.UUCP (randy orrison) Organization: Control Data in the Hills of Arden, Minnesota Lines: 31 In article <468@auspex.UUCP> guy@auspex.UUCP (Guy Harris) writes: |>|#define gets(s) fgets(s, sizeof s, stdin) |... |> gets (s); | |>Two problems: the space after gets would kill it if it's a macro, | |Say WHAT? Works fine on all the compilers I know of. "Preprocessor" |macros don't require that you give the exact same amount of white space |in the invocation as you gave in the definition; if your compiler |requires this, get it fixed! Obviously correct. (Sorry Brandon!) What I was thinking of was the time i tried something along the lines of: #define gets (s) fgets(s, sizeof s, stdin) ^ which fails for obvious reasons. However, it still doesn't work for cases where s is a pointer instead of an array - say, if it's a parameter in a function, or declared as a char * with memory allocated for it. It's not something you could stick in at the top of someone else's code to make it secure, and it's not something you'd want to use in original code (which you could do right). -randy -- Randy Orrison - Control Data in the Hills of Arden randy@halcdc.uucp aka randy@{ux.acss.umn.edu, umnacvx.bitnet, cctb.mn.org, umn-cs.uucp} ZQOTD: "Yow! It's a hole all the way to downtown Burbank!"