From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 84FAA3858D35; Mon, 27 Jul 2020 08:14:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 84FAA3858D35 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] riscv: fix integer wraparound in memcpy X-Act-Checkin: newlib-cygwin X-Git-Author: PkmX via Newlib X-Git-Refname: refs/heads/master X-Git-Oldrev: 0947efb859110d0bbe4b6f1ddc9a762613e662a8 X-Git-Newrev: 123b8065237a3fb644528d3e95216ade336334bd Message-Id: <20200727081453.84FAA3858D35@sourceware.org> Date: Mon, 27 Jul 2020 08:14:53 +0000 (GMT) X-BeenThere: newlib-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib GIT logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Jul 2020 08:14:53 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=123b8065237a3fb644528d3e95216ade336334bd commit 123b8065237a3fb644528d3e95216ade336334bd Author: PkmX via Newlib Date: Fri Jul 24 19:07:45 2020 +0800 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 Diff: --- newlib/libc/machine/riscv/memcpy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/newlib/libc/machine/riscv/memcpy.c b/newlib/libc/machine/riscv/memcpy.c index 07e8e0076..4098f3ab1 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++;