Skip to content

Commit ca5d067

Browse files
andreas-schwabozbenh
authored andcommitted
powerpc: Fix string library functions
The powerpc strncmp implementation does not correctly handle a zero length, despite the claim in 0119536 (Add hand-coded assembly strcmp). Additionally, all the length arguments are size_t, not int, so use PPC_LCMPI and eq instead of cmpwi and le throughout. Signed-off-by: Andreas Schwab <schwab@linux-m68k.org> Acked-by: Paul Mackerras <paulus@samba.org> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
1 parent 7358650 commit ca5d067

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

‎arch/powerpc/lib/string.S‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ _GLOBAL(strcpy)
2828
/* This clears out any unused part of the destination buffer,
2929
just as the libc version does. -- paulus */
3030
_GLOBAL(strncpy)
31-
cmpwi 0,r5,0
31+
PPC_LCMPI 0,r5,0
3232
beqlr
3333
mtctr r5
3434
addi r6,r3,-1
@@ -39,7 +39,7 @@ _GLOBAL(strncpy)
3939
bdnzf 2,1b /* dec ctr, branch if ctr != 0 && !cr0.eq */
4040
bnelr /* if we didn't hit a null char, we're done */
4141
mfctr r5
42-
cmpwi 0,r5,0 /* any space left in destination buffer? */
42+
PPC_LCMPI 0,r5,0 /* any space left in destination buffer? */
4343
beqlr /* we know r0 == 0 here */
4444
2: stbu r0,1(r6) /* clear it out if so */
4545
bdnz 2b
@@ -70,8 +70,8 @@ _GLOBAL(strcmp)
7070
blr
7171

7272
_GLOBAL(strncmp)
73-
PPC_LCMPI r5,0
74-
ble- 2f
73+
PPC_LCMPI 0,r5,0
74+
beq- 2f
7575
mtctr r5
7676
addi r5,r3,-1
7777
addi r4,r4,-1
@@ -94,8 +94,8 @@ _GLOBAL(strlen)
9494
blr
9595

9696
_GLOBAL(memcmp)
97-
cmpwi 0,r5,0
98-
ble- 2f
97+
PPC_LCMPI 0,r5,0
98+
beq- 2f
9999
mtctr r5
100100
addi r6,r3,-1
101101
addi r4,r4,-1
@@ -108,8 +108,8 @@ _GLOBAL(memcmp)
108108
blr
109109

110110
_GLOBAL(memchr)
111-
cmpwi 0,r5,0
112-
ble- 2f
111+
PPC_LCMPI 0,r5,0
112+
beq- 2f
113113
mtctr r5
114114
addi r3,r3,-1
115115
1: lbzu r0,1(r3)

0 commit comments

Comments
 (0)