[newlib-cygwin/main] libc: mips: fix strcmp bug for little endian targets

Jeff Johnston jjohnstn@sourceware.org
Sat Jul 5 01:26:56 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=571dbf20946732ce40ca4f9aaff69826fc31a108

commit 571dbf20946732ce40ca4f9aaff69826fc31a108
Author: Faraz Shahbazker <fshahbazker@wavecomp.com>
Date:   Tue Sep 24 21:59:46 2019 -0700

    libc: mips: fix strcmp bug for little endian targets
    
    strcmp gives incorrect result for little endian targets under
    the following conditions:
    1. Length of 1st string is 1 less than a multiple of 4 (i.e len%4=3)
    2. First string is a prefix of the second string
    3. The first differing character in the second string is extended
    ASCII (that is > 127)
    
    Signed-off-by: Jovan Dmitrović <jovan.dmitrovic@htecgroup.com>

Diff:
---
 newlib/libc/machine/mips/strcmp.S | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/newlib/libc/machine/mips/strcmp.S b/newlib/libc/machine/mips/strcmp.S
index 126344d6c..07b988a57 100644
--- a/newlib/libc/machine/mips/strcmp.S
+++ b/newlib/libc/machine/mips/strcmp.S
@@ -217,10 +217,13 @@ L(worddiff):
 	beq	a0, zero, L(wexit01)
 	bne	a0, a1, L(wexit01)
 
-	/* The other bytes are identical, so just subract the 2 words
-	  and return the difference.  */
+# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+	srl a0, a2, 24
+	srl a1, a3, 24
+# else /* __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ */
 	move a0, a2
 	move a1, a3
+# endif /* __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ */
 
 L(wexit01):
 	subu	va0, a0, a1


More information about the Newlib-cvs mailing list