From 214f9558c301b8c588d5d2fc21fb3768cf31c550 Mon Sep 17 00:00:00 2001 From: Dale Rahn Date: Sun, 3 May 2009 05:09:41 +0000 Subject: Fix signed vs unsigned issue with memcmp/strncmp where the size parameter was incorrectly being treated as signed. ok miod@ --- lib/libc/arch/arm/string/memcmp.S | 13 ++++++++----- lib/libc/arch/arm/string/strncmp.S | 13 ++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) (limited to 'lib/libc/arch') diff --git a/lib/libc/arch/arm/string/memcmp.S b/lib/libc/arch/arm/string/memcmp.S index 1c0045d4df2..866a31d1f8b 100644 --- a/lib/libc/arch/arm/string/memcmp.S +++ b/lib/libc/arch/arm/string/memcmp.S @@ -1,4 +1,4 @@ -/* $OpenBSD: memcmp.S,v 1.2 2004/02/01 05:40:52 drahn Exp $ */ +/* $OpenBSD: memcmp.S,v 1.3 2009/05/03 05:09:40 drahn Exp $ */ /* $NetBSD: memcmp.S,v 1.2 2003/04/05 23:08:52 bjh21 Exp $ */ /* @@ -34,10 +34,13 @@ RCSID("$NetBSD: memcmp.S,v 1.2 2003/04/05 23:08:52 bjh21 Exp $") ENTRY(memcmp) -/* if ((len - 1) < 0) return 0 */ - subs r2, r2, #1 - movmi r0, #0 - movmi pc, lr +/* if (len == 0) return 0 */ + cmp r2, #0 + moveq r0, #0 + moveq pc, lr + +/* subtract one to have the index of the last character to check */ + sub r2, r2, #1 /* ip == last src address to compare */ add ip, r0, r2 diff --git a/lib/libc/arch/arm/string/strncmp.S b/lib/libc/arch/arm/string/strncmp.S index 1473442ff14..f8960bbc84b 100644 --- a/lib/libc/arch/arm/string/strncmp.S +++ b/lib/libc/arch/arm/string/strncmp.S @@ -1,4 +1,4 @@ -/* $OpenBSD: strncmp.S,v 1.3 2005/08/07 16:40:14 espie Exp $ */ +/* $OpenBSD: strncmp.S,v 1.4 2009/05/03 05:09:40 drahn Exp $ */ /* $NetBSD: strncmp.S,v 1.2 2003/04/05 23:08:52 bjh21 Exp $ */ /* @@ -32,10 +32,13 @@ #include ENTRY(strncmp) -/* if ((len - 1) < 0) return 0 */ - subs r2, r2, #1 - movmi r0, #0 - movmi pc, lr +/* if (len == 0) return 0 */ + cmp r2, #0 + moveq r0, #0 + moveq pc, lr + +/* subtract one to have the index of the last character to check */ + sub r2, r2, #1 /* ip == last src address to compare */ add ip, r0, r2 -- cgit v1.2.3