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/arm/string Fix corner cases when search...



details:   https://anonhg.NetBSD.org/src/rev/5fd4324aa15b
branches:  trunk
changeset: 784739:5fd4324aa15b
user:      matt <matt%NetBSD.org@localhost>
date:      Fri Feb 08 02:19:35 2013 +0000

description:
Fix corner cases when searching for NUL.

diffstat:

 common/lib/libc/arch/arm/string/strchr_arm.S  |   4 +++-
 common/lib/libc/arch/arm/string/strrchr_arm.S |  16 ++++++++++++----
 2 files changed, 15 insertions(+), 5 deletions(-)

diffs (61 lines):

diff -r c80fc525380c -r 5fd4324aa15b common/lib/libc/arch/arm/string/strchr_arm.S
--- a/common/lib/libc/arch/arm/string/strchr_arm.S      Fri Feb 08 01:54:20 2013 +0000
+++ b/common/lib/libc/arch/arm/string/strchr_arm.S      Fri Feb 08 02:19:35 2013 +0000
@@ -29,7 +29,7 @@
 
 #include <machine/asm.h>
 
-RCSID("$NetBSD: strchr_arm.S,v 1.4 2013/02/07 01:20:29 matt Exp $")
+RCSID("$NetBSD: strchr_arm.S,v 1.5 2013/02/08 02:19:35 matt Exp $")
 
 #ifdef __ARMEL__
 #define        BYTE0   0x000000ff
@@ -90,6 +90,8 @@
         * We've encountered a NUL or a match but we don't know which happened
         * first.
         */
+       teq     r2, #0                  /* searching for NUL? */
+       beq     .Lfind_match            /*   yes, find the match */
        mvns    ip, ip                  /* did we encounter a NUL? */
        beq     .Lfind_match            /*   no, find the match */
        bics    r3, r3, ip              /* clear match for the NUL(s) */
diff -r c80fc525380c -r 5fd4324aa15b common/lib/libc/arch/arm/string/strrchr_arm.S
--- a/common/lib/libc/arch/arm/string/strrchr_arm.S     Fri Feb 08 01:54:20 2013 +0000
+++ b/common/lib/libc/arch/arm/string/strrchr_arm.S     Fri Feb 08 02:19:35 2013 +0000
@@ -29,7 +29,7 @@
 
 #include <machine/asm.h>
 
-RCSID("$NetBSD: strrchr_arm.S,v 1.2 2013/01/28 06:23:14 matt Exp $")
+RCSID("$NetBSD: strrchr_arm.S,v 1.3 2013/02/08 02:19:36 matt Exp $")
 
 #ifdef __ARMEL__
 #define        BYTE0   0x000000ff
@@ -47,16 +47,24 @@
 
        .text
 ENTRY(strrchr)
-       mov     ip, r0                  /* we use r0 at the return value */
+       teq     r1, #0                  /* searching for NUL? */
+       bne     1f                      /*   no, do it the hard way */
+       push    {r0, lr}                /* save pointer and return addr */
+       bl      PLT_SYM(strlen)         /* get length */
+       pop     {r1, lr}                /* restore pointer and returna addr */
+       add     r0, r0, r1              /* add pointer to length */
+       RET                             /* return */
+
+1:     mov     ip, r0                  /* we use r0 at the return value */
        mov     r0, #0                  /* return NULL by default */
        and     r2, r1, #0xff           /* restrict to byte value */
-1:     tst     ip, #3                  /* test for word alignment */
+2:     tst     ip, #3                  /* test for word alignment */
        beq     .Lpre_main_loop         /*   finally word aligned */
        ldrb    r3, [ip], #1            /* load a byte */
        cmp     r3, r2                  /* did it match? */
        subeq   r0, ip, #1              /*   yes, remember that it did */
        teq     r3, #0                  /* was it NUL? */
-       bne     1b                      /*   no, try next byte */
+       bne     2b                      /*   no, try next byte */
        RET                             /* return */
 .Lpre_main_loop:
        push    {r4, r5}                /* save some registers */



Home | Main Index | Thread Index | Old Index