[coreboot] r3519 - trunk/payloads/libpayload/libc
Stefan Reinauer
stepan at coresystems.de
Tue Aug 19 20:57:42 CEST 2008
Ulf Jordan wrote:
> On Tue, 19 Aug 2008, svn at coreboot.org wrote:
>
> [snip]
>
>> void *memcpy(void *dst, const void *src, size_t n)
>> {
>> - int i, j;
>> + int i;
>>
>> - if (((long)dst & (sizeof(long) - 1))
>> - || ((long)src & (sizeof(long) - 1)))
>> - return unaligned_memcpy(dst, src, n);
>> + for(i = 0; i < n % sizeof(unsigned long); i++)
>> + ((unsigned char *) dst)[i] = ((unsigned char *) src)[i];
>>
>> - for (i = 0; i < n / sizeof(unsigned long); i++)
>> - ((unsigned long *)dst)[i] = ((unsigned long *)src)[i];
>> + n -= i;
>> + src += i;
>> + dst += i;
>>
>> - for (j = 0; j < n % sizeof(unsigned long); j++)
>> - ((unsigned char *)(((unsigned long *)dst) + i))[j] =
>> - ((unsigned char *)(((unsigned long *)src) + i))[j];
>> + for(i = 0; i < n / sizeof(unsigned long); i++)
>> + ((unsigned long *) dst)[i] = ((unsigned long *) src)[i];
>>
>> - return (char *)src;
>> + return dst;
>> }
>
> Does this really return the correct value?
>
> When I read the Linux memcpy(3) man page and the GNU C library reference
> manual I get the impression that the return value should be the original
> value of dst. This implementation returns a value which is original
> dst+0,
> 1, 2, or 3, depending on n % sizeof(unsigned long).
good catch. This is wrong.
--
coresystems GmbH • Brahmsstr. 16 • D-79104 Freiburg i. Br.
Tel.: +49 761 7668825 • Fax: +49 761 7664613
Email: info at coresystems.de • http://www.coresystems.de/
Registergericht: Amtsgericht Freiburg • HRB 7656
Geschäftsführer: Stefan Reinauer • Ust-IdNr.: DE245674866
More information about the coreboot
mailing list