[U-Boot-Users] [PATCH 02/17] examples/eepro100_eeprom: Fix memcpy to return destination pointer
Wolfgang Denk
wd at denx.de
Mon May 19 01:03:36 CEST 2008
In message <20080518222019.GC19480 at 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.
we can do this
>
> char *tmp = dst;
>
> while (len-- > 0) {
> *tmp++ = *((char *)src);
> src++;
> }
>
> return (void *)dst;
This is not a bit better.
Best regards,
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
As far as the laws of mathematics refer to reality, they are not cer-
tain, and as far as they are certain, they do not refer to reality.
-- Albert Einstein
More information about the U-Boot
mailing list