From: Wolfgang Denk Date: Mon, 23 May 2011 23:55:33 +0200 Subject: [U-Boot] [PATCH V2] memcpy/memmove: Do not copy to same address In-Reply-To: <4DDACC8B.6090507@ahsoftware.de> References: <1302591520-12517-1-git-send-email-weisserm@arcor.de> <1306141435-24001-1-git-send-email-weisserm@arcor.de> <4DDACC8B.6090507@ahsoftware.de> Message-ID: <20110523215533.7B6FCCF5CA6@gemini.denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Dear Alexander Holler, In message <4DDACC8B.6090507@ahsoftware.de> you wrote: > > > --- a/lib/string.c > > +++ b/lib/string.c > > @@ -467,6 +467,9 @@ void * memcpy(void *dest, const void *src, size_t count) > > unsigned long *dl = (unsigned long *)dest, *sl = (unsigned long *)src; > > char *d8, *s8; > > > > + if (src == dest) > > + return dest; > > + > > here is the same, as in the patch I've commented before. There exist no > reason to add a check for identity to memcpy() because memcpy doesn't > support overlapping regions (and identity is just a special case of > overlapping regions). If something might call memcpy() with overlapping > or identical regions, it should use memmove(). In an ideal world, nobody will ever use any interfces in a non-compliant or incorrect way. In reality, all kind of errors happen. A little defensive programming like the one above helps a lot, so please stop complaining even if you think you don't need this. Thanks. Wolfgang Denk -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de Mirrors should reflect a little before throwing back images. - Jean Cocteau