summaryrefslogtreecommitdiff
path: root/lib/libc/arch
diff options
context:
space:
mode:
authorDale Rahn <drahn@cvs.openbsd.org>2009-05-03 05:09:41 +0000
committerDale Rahn <drahn@cvs.openbsd.org>2009-05-03 05:09:41 +0000
commit214f9558c301b8c588d5d2fc21fb3768cf31c550 (patch)
treef5b0797e85db119e0e64dcfadde148c5b61fc910 /lib/libc/arch
parent4859f9b7812e778554340fae89158ac857cb8c28 (diff)
Fix signed vs unsigned issue with memcmp/strncmp where the size parameter
was incorrectly being treated as signed. ok miod@
Diffstat (limited to 'lib/libc/arch')
-rw-r--r--lib/libc/arch/arm/string/memcmp.S13
-rw-r--r--lib/libc/arch/arm/string/strncmp.S13
2 files changed, 16 insertions, 10 deletions
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 <machine/asm.h>
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