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 strnlen(s, (size_t)-1) r...



details:   https://anonhg.NetBSD.org/src/rev/26b57ae194bb
branches:  trunk
changeset: 991823:26b57ae194bb
user:      ryo <ryo%NetBSD.org@localhost>
date:      Wed Aug 01 17:09:26 2018 +0000

description:
strnlen(s, (size_t)-1) returned -1. it must return the length of s.

diffstat:

 common/lib/libc/arch/aarch64/string/strlen.S |  13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diffs (48 lines):

diff -r 02f17ceb8252 -r 26b57ae194bb common/lib/libc/arch/aarch64/string/strlen.S
--- a/common/lib/libc/arch/aarch64/string/strlen.S      Wed Aug 01 16:59:09 2018 +0000
+++ b/common/lib/libc/arch/aarch64/string/strlen.S      Wed Aug 01 17:09:26 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: strlen.S,v 1.2 2017/08/22 06:45:07 ryo Exp $ */
+/* $NetBSD: strlen.S,v 1.3 2018/08/01 17:09:26 ryo Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <machine/asm.h>
 
-RCSID("$NetBSD: strlen.S,v 1.2 2017/08/22 06:45:07 ryo Exp $")
+RCSID("$NetBSD: strlen.S,v 1.3 2018/08/01 17:09:26 ryo Exp $")
 
 #ifdef STRNLEN
 #define FUNCNAME       strnlen
@@ -49,7 +49,10 @@
        add     x9, x0, #8              /* start + dword */
        bic     x9, x9, #7              /* and aligned */
 #ifdef STRNLEN
-       add     x10, x0, x1             /* don't go past here */
+       adds    x10, x0, x1             /* x10 = s + maxlen */
+       b.cc    1f                      /* if go past, */
+       mvn     x10, xzr                /* set limit 0xffffffffffffffff */
+1:
 #endif
        mov     x11, #MASK8_0x01        /* test mask */
 
@@ -76,7 +79,7 @@
 .Lstrlen_dword_loop:
 #ifdef STRNLEN
        cmp     x4, x10
-       b.ge    .Lstrlen_done
+       b.hs    .Lstrlen_done
 #endif
        ldr     x7, [x4], #8            /* load dword */
 .Lstrlen_dword_loop_noload:
@@ -103,7 +106,7 @@
        sub     x0, x0, x9              /* subtract start from the length */
 #ifdef STRNLEN
        cmp     x0, x1                  /* did we go too far? */
-       csel    x0, x0, x1, lt          /* yes, return max length */
+       csel    x0, x0, x1, lo          /* yes, return max length */
 #endif
        ret
 #ifdef STRNLEN



Home | Main Index | Thread Index | Old Index