This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: cpplib: patch: three long-standing bugs
- To: Zack Weinberg <zack at bitmover dot com>
- Subject: Re: cpplib: patch: three long-standing bugs
- From: Jeff Garzik <jgarzik at pobox dot com>
- Date: Sat, 04 Sep 1999 23:23:35 -0400
- CC: gcc-patches at gcc dot gnu dot org
- Organization: none
- References: <199909050228.TAA21313@zack.bitmover.com>
Zack Weinberg wrote:
> 3) xstrdup does need to be modified, but not the way you did it. The
> proper change is
>
> @@ -74,8 +74,8 @@ char *
> xstrdup (input)
> const char *input;
> {
> - unsigned size = strlen (input);
> - char *output = xmalloc (size + 1);
> - strcpy (output, input);
> + size_t size = strlen (input) + 1;
> + char *output = xmalloc (size);
> + memcpy (output, input, size);
> return output;
> }
>
> Do you see why this version is better?
Yes.
cpplib code has to be portable, right? I don't think all compilers can
call functions from variable declarations IIRC.
Thanks for the feedback.
Jeff
--
Custom driver development | Never worry about theory as long
Open source programming | as the machinery does what it's
| supposed to do. -- R. A. Heinlein