From 24bb5fcea3ed904bc467217bdaadb5dfc618d5bf Mon Sep 17 00:00:00 2001 From: visa Date: Sat, 24 Jul 2021 05:35:56 +0000 Subject: [PATCH] Fix strchr() and strrchr() on mips64 Truncate the character arguments of strchr() and strrchr() to eight bits so that the implied char conversion would work correctly. Otherwise the functions would always return NULL when the character argument is negative. OK miod@ --- lib/libc/arch/mips64/string/strchr.S | 3 ++- lib/libc/arch/mips64/string/strrchr.S | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/libc/arch/mips64/string/strchr.S b/lib/libc/arch/mips64/string/strchr.S index 05f50f0da73..fb85f700e8e 100644 --- a/lib/libc/arch/mips64/string/strchr.S +++ b/lib/libc/arch/mips64/string/strchr.S @@ -1,4 +1,4 @@ -/* $OpenBSD: strchr.S,v 1.3 2015/08/31 02:53:56 guenther Exp $ */ +/* $OpenBSD: strchr.S,v 1.4 2021/07/24 05:35:56 visa Exp $ */ /*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. @@ -37,6 +37,7 @@ WEAK_ALIAS(index, strchr) LEAF(strchr, 0) .set reorder + andi a1, 0xff 0: lbu a2, 0(a0) # get a byte daddu a0, a0, 1 diff --git a/lib/libc/arch/mips64/string/strrchr.S b/lib/libc/arch/mips64/string/strrchr.S index ad35b84cb95..a7a4a5996c1 100644 --- a/lib/libc/arch/mips64/string/strrchr.S +++ b/lib/libc/arch/mips64/string/strrchr.S @@ -1,4 +1,4 @@ -/* $OpenBSD: strrchr.S,v 1.3 2015/08/31 02:53:56 guenther Exp $ */ +/* $OpenBSD: strrchr.S,v 1.4 2021/07/24 05:35:56 visa Exp $ */ /*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. @@ -38,6 +38,7 @@ WEAK_ALIAS(rindex, strrchr) LEAF(strrchr, 0) .set reorder move v0, zero # default if not found + andi a1, 0xff 1: lbu a3, 0(a0) # get a byte daddu a0, a0, 1 -- 2.20.1