aboutsummaryrefslogtreecommitdiff
path: root/newlib
diff options
context:
space:
mode:
authorPkmX via Newlib <newlib@sourceware.org>2020-07-24 19:07:45 +0800
committerCorinna Vinschen <corinna@vinschen.de>2020-07-27 10:14:34 +0200
commit123b8065237a3fb644528d3e95216ade336334bd (patch)
tree45fa660896664f4669339956a7fb626e8666946e /newlib
parent0947efb859110d0bbe4b6f1ddc9a762613e662a8 (diff)
downloadnewlib-123b8065237a3fb644528d3e95216ade336334bd.zip
newlib-123b8065237a3fb644528d3e95216ade336334bd.tar.gz
newlib-123b8065237a3fb644528d3e95216ade336334bd.tar.bz2
riscv: fix integer wraparound in memcpy
This patch fixes a bug in RISC-V's memcpy implementation where an integer wraparound occurs when src + size < 8 * sizeof(long), causing the word-sized copy loop to be incorrectly entered. Signed-off-by: Chih-Mao Chen <cmchen@andestech.com>
Diffstat (limited to 'newlib')
-rw-r--r--newlib/libc/machine/riscv/memcpy.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/newlib/libc/machine/riscv/memcpy.c b/newlib/libc/machine/riscv/memcpy.c
index 07e8e00..4098f3a 100644
--- a/newlib/libc/machine/riscv/memcpy.c
+++ b/newlib/libc/machine/riscv/memcpy.c
@@ -51,9 +51,9 @@ small:
const long *lb = (const long *)b;
long *lend = (long *)((uintptr_t)end & ~msk);
- if (unlikely (la < (lend - 8)))
+ if (unlikely (lend - la > 8))
{
- while (la < (lend - 8))
+ while (lend - la > 8)
{
long b0 = *lb++;
long b1 = *lb++;