From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jerry Van Baren Date: Sun, 18 May 2008 22:38:33 -0400 Subject: [U-Boot-Users] [PATCH 02/17] examples/eepro100_eeprom: Fix memcpy to return destination pointer In-Reply-To: <20080519012211.GD19480@game.jcrosoft.org> References: <20080518222019.GC19480@game.jcrosoft.org> <20080518230336.5DA772476E@gemini.denx.de> <20080519012211.GD19480@game.jcrosoft.org> Message-ID: <4830E829.7020100@gmail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Jean-Christophe PLAGNIOL-VILLARD wrote: > On 01:03 Mon 19 May , Wolfgang Denk wrote: >> In message <20080518222019.GC19480@game.jcrosoft.org> you wrote: >>>>> static inline void *memcpy(void *dst, const void *src, unsigned int len) >>>>> { >>>>> char *ret = dst; >>>>> + >>>>> while (len-- > 0) { >>>>> *ret++ = *((char *)src); >>>>> src++; >>>>> } >>>>> - return (void *)ret; >>>>> + >>>>> + return (void *)dst; >>>> While technically correct, this is bogus. We have a variable ret, but >>>> we don't return it. And we have a variable dst, but we don't use it as >>>> destination pointer. >>>> >>>> Please change the >>>> *ret++ = *((char *)src); >>>> into >>>> *dst++ = *((char *)src); >>>> and leave all the rest. >>> You can not do this because dst is a void >> Why not? src is void, too. > gcc will claim about the cast. > > we can do this > void *ret = dst; > char *d = dst; > const char *s = src; > > while (len-- > 0) > *d++ = *s++; > > return ret; > > Best Regards, > J. YES! YES! YES! This gets my vote. I marked the start of this thread meaning to suggest using temp variables of the right type and get rid of the complex casting crap, exactly what you did here. Thanks, gvb