This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: strcpy -> memcpy


Hi Ian,

On Tue, Jun 25, 2002 at 11:21:30AM -0700, Ian Lance Taylor wrote:

> 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.

Ok. Thanks for the response.

Elias


ChangeLog/gas

2002-06-25  Elias Athanasopoulos  <eathan@otenet.gr>

	* ecoff.c (get_tag): Replace strcpy with xstrdup.
	(ecoff_directive_def): Likewise.
	(ecoff_directive_tag): Likewise.
	* listing.c (file_info): Likewise.
	* hash.c (what): Replace strcpy with memcpy.


--- ecoff.c.orig	Tue Jun 25 22:29:15 2002
+++ ecoff.c	Tue Jun 25 22:31:07 2002
@@ -2037,8 +2037,7 @@
     {
       char *perm;
 
-      perm = xmalloc ((unsigned long) (strlen (tag) + 1));
-      strcpy (perm, tag);
+      perm = xstrdup (tag);
       hash_ptr = allocate_shash ();
       err = hash_insert (tag_hash, perm, (char *) hash_ptr);
       if (err)
@@ -2545,8 +2544,8 @@
 	free (coff_sym_name);
       if (coff_tag != (char *) NULL)
 	free (coff_tag);
-      coff_sym_name = (char *) xmalloc ((unsigned long) (strlen (name) + 1));
-      strcpy (coff_sym_name, name);
+      
+      coff_sym_name = xstrdup (name);
       coff_type = type_info_init;
       coff_storage_class = sc_Nil;
       coff_symbol_typ = st_Nil;
@@ -2778,8 +2777,7 @@
   name = input_line_pointer;
   name_end = get_symbol_end ();
 
-  coff_tag = (char *) xmalloc ((unsigned long) (strlen (name) + 1));
-  strcpy (coff_tag, name);
+  coff_tag = xstrdup (name);
 
   *input_line_pointer = name_end;
 

--- listing.c.orig	Tue Jun 25 22:37:38 2002
+++ listing.c	Tue Jun 25 22:37:41 2002
@@ -269,8 +269,7 @@
   p = (file_info_type *) xmalloc (sizeof (file_info_type));
   p->next = file_info_head;
   file_info_head = p;
-  p->filename = xmalloc ((unsigned long) strlen (file_name) + 1);
-  strcpy (p->filename, file_name);
+  p->filename = xstrdup (file_name);
   p->pos = 0;
   p->linenum = 0;
   p->at_end = 0;


--- hash.c.orig	Tue Jun 25 22:35:08 2002
+++ hash.c	Tue Jun 25 22:34:55 2002
@@ -547,17 +547,16 @@
      char *description;
 {
   char *retval;
-  char *malloc ();
+  size_t len;
 
   printf ("   %s : ", description);
   gets (answer);
   /* Will one day clean up answer here.  */
-  retval = malloc (strlen (answer) + 1);
+  len = strlen (answer) + 1;
+  retval = malloc (len);
   if (!retval)
-    {
-      error ("room");
-    }
-  (void) strcpy (retval, answer);
+    error ("room"); 
+  memcpy (retval, answer, len);
   return (retval);
 }
 










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