Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/common/lib/libc/arch/aarch64/string Fix a broken corner case...
details: https://anonhg.NetBSD.org/src/rev/b734353ce098
branches: trunk
changeset: 954533:b734353ce098
user: jakllsch <jakllsch%NetBSD.org@localhost>
date: Sat Sep 05 20:24:43 2020 +0000
description:
Fix a broken corner case of strlen()/strnlen() on aarch64eb
Previously a string such as "\x1\x1\x1\x1\x1\x1\x1" would count as
0 instead of 7 on BE.
diffstat:
common/lib/libc/arch/aarch64/string/strlen.S | 14 ++++++++++----
1 files changed, 10 insertions(+), 4 deletions(-)
diffs (36 lines):
diff -r 84a0114cf878 -r b734353ce098 common/lib/libc/arch/aarch64/string/strlen.S
--- a/common/lib/libc/arch/aarch64/string/strlen.S Sat Sep 05 19:17:42 2020 +0000
+++ b/common/lib/libc/arch/aarch64/string/strlen.S Sat Sep 05 20:24:43 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: strlen.S,v 1.3 2018/08/01 17:09:26 ryo Exp $ */
+/* $NetBSD: strlen.S,v 1.4 2020/09/05 20:24:43 jakllsch Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <machine/asm.h>
-RCSID("$NetBSD: strlen.S,v 1.3 2018/08/01 17:09:26 ryo Exp $")
+RCSID("$NetBSD: strlen.S,v 1.4 2020/09/05 20:24:43 jakllsch Exp $")
#ifdef STRNLEN
#define FUNCNAME strnlen
@@ -96,9 +96,15 @@
/*
* We know there is a NUL in this dword. Use clz to find it.
*/
-#ifdef __AARCH64EL__
+#ifdef __AARCH64EB__
+ /* avoid BE problem due to carry propagation if last non-NUL is \x01 */
+ ldr x7, [x4, #-8] /* reload dword */
+ rev x7, x7 /* byte swap */
+ sub x6, x7, x11 /* a = X - 1 */
+ orr x7, x7, #MASK8_0x7f /* b = X | 0x7f */
+ bic x6, x6, x7 /* a & ~b */
+#endif
rev x6, x6 /* convert to BE */
-#endif
clz x6, x6 /* find null byte */
add x0, x0, x6, lsr #3 /* add offset to the length */
Home |
Main Index |
Thread Index |
Old Index