This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: patch to clean out savestring, copystr, mybzero and mybcopy


On Tue, Jan 12, 1999 at 10:42:19AM -0500, Kaveh R. Ghazi wrote:
> 	Here is a new copy of the patch.  Okay to install?

Yes.  One comment though --

> +xstrdup (input)
> +  const char *input;
>  {
> +  register char *output = xmalloc (strlen (input) + 1);
>    strcpy (output, input);
>    return output;
>  }

This is better implemented

  size_t len = strlen (input) + 1;
  char *output = xmalloc (len);
  return memcpy (output, input, len);

In this way we only search for the null terminator once.


r~


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]