[U-Boot-Users] [PATCH 02/17] examples/eepro100_eeprom: Fix memcpy to return destination pointer

Jean-Christophe PLAGNIOL-VILLARD plagnioj at jcrosoft.com
Mon May 19 00:20:19 CEST 2008


On 00:28 Mon 19 May     , Wolfgang Denk wrote:
> In message <1211130599-28289-3-git-send-email-plagnioj at jcrosoft.com> you wrote:
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
> > ---
> >  examples/eepro100_eeprom.c |    5 ++++-
> >  1 files changed, 4 insertions(+), 1 deletions(-)
> > 
> > diff --git a/examples/eepro100_eeprom.c b/examples/eepro100_eeprom.c
> > index 2b15d05..5f4eb78 100644
> > --- a/examples/eepro100_eeprom.c
> > +++ b/examples/eepro100_eeprom.c
> > @@ -80,11 +80,13 @@ static inline short inw(long addr)
> >  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

we can do this

	char *tmp = dst;

	while (len-- > 0) {
		*tmp++ = *((char *)src);
		src++;
	}

	return (void *)dst;

Best Regards,
J.




More information about the U-Boot mailing list