This is the mail archive of the binutils@sourceware.org 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: Fix valgrind nm complaint: memcpy to == from


> Date: Thu, 13 Nov 2008 04:23:26 +0100
> From: Hans-Peter Nilsson <hp@axis.com>
> > Date: Thu, 13 Nov 2008 13:46:47 +1030
> > From: Alan Modra <amodra@bigpond.net.au>
> > I think it's better to use
> > 	  if (to != from)
> > 	    memcpy (to, from, size);

This is what I tested and checked in.

binutils:
	* nm.c (filter_symbols): Only call memcpy when from != to.

Index: nm.c
===================================================================
RCS file: /cvs/src/src/binutils/nm.c,v
retrieving revision 1.55
diff -p -u -r1.55 nm.c
--- nm.c	13 Sep 2007 14:32:11 -0000	1.55
+++ nm.c	13 Nov 2008 10:53:31 -0000
@@ -449,7 +449,8 @@ filter_symbols (bfd *abfd, bfd_boolean d
 
       if (keep)
 	{
-	  memcpy (to, from, size);
+	  if (to != from)
+	    memcpy (to, from, size);
 	  to += size;
 	}
     }

brgds, H-P


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