From: Sebastien Bourdeauducq Date: Sun, 27 May 2012 13:45:45 +0000 (+0200) Subject: software/libbase: fix memcpy handling of buffers with differing alignments X-Git-Tag: 24jan2021_ls180~3157 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=48b70f09a87ae5c06e62fc29ecd2d480e8b4198d;p=litex.git software/libbase: fix memcpy handling of buffers with differing alignments --- diff --git a/software/libbase/libc.c b/software/libbase/libc.c index 78e3823f..d0667f1c 100644 --- a/software/libbase/libc.c +++ b/software/libbase/libc.c @@ -265,6 +265,13 @@ void *memcpy(void *to, const void *from, size_t n) from = cfrom; n--; } + if((long)from & 1) { + char *cto = to; + const char *cfrom = from; + for (; n; n--) + *cto++ = *cfrom++; + return xto; + } if(n > 2 && (long)to & 2) { short *sto = to; const short *sfrom = from; @@ -278,7 +285,7 @@ void *memcpy(void *to, const void *from, size_t n) long *lto = to; const long *lfrom = from; for(; temp; temp--) - *lto++ = *lfrom++; + *lto++ = *lfrom++; to = lto; from = lfrom; }