strcpy -> memcpy

Ian Lance Taylor ian@airs.com
Tue Jun 25 11:21:00 GMT 2002


Elias Athanasopoulos <eathan@otenet.gr> writes:

> I fixed some similar cases in gas. You might want to include them.
> 
> Elias
> 
> ChangeLog/gas
> 
> 2002-06-25  Elias Athanasopoulos  <eathan@otenet.gr>
> 
> 	* ecoff.c (get_tag): Replace strcpy with memcpy.
> 	(ecoff_directive_def): Likewise.
> 	(ecoff_directive_tag): Likewise.
> 	* listing.c (file_info): Likewise.
> 	* hash.c (what): Likewise.
> 
> --- ecoff.c.orig	Tue Jun 25 19:17:30 2002
> +++ ecoff.c	Tue Jun 25 19:39:29 2002
> @@ -2036,9 +2036,13 @@
>    if (hash_ptr == (shash_t *) NULL)
>      {
>        char *perm;
> +      size_t len;
>  
> -      perm = xmalloc ((unsigned long) (strlen (tag) + 1));
> -      strcpy (perm, tag);
> +      len = strlen (tag) + 1;
> +      perm = xmalloc (len);
> +      if (!perm)
> +	return false;
> +      memcpy (perm, tag, len);
>        hash_ptr = allocate_shash ();
>        err = hash_insert (tag_hash, perm, (char *) hash_ptr);
>        if (err)

Now this is a place where we should use xstrdup.  And note that
xmalloc can not return NULL, so there is no reason for check for it.

Ian



More information about the Binutils mailing list