[PATCH 1/2] riscv: Fix character conversion in RVV strrchr
Chengrong Dai
daichengrong@iscas.ac.cn
Mon Nov 23 08:11:37 GMT 2026
From: daichengrong <daichengrong@iscas.ac.cn>
The RVV strrchr implementation checks the full int argument for zero
before converting it to a character. Nonzero arguments such as 256
and -256 therefore skip the zero-search path, and the ordinary path
excludes the terminating NUL, incorrectly returning NULL.
Truncate the argument to eight bits before the zero check so arguments
that convert to NUL take the zero-search path.
Co-authored-by: Yuansheng <yuansheng@isrc.iscas.ac.cn>
Signed-off-by: daichengrong <daichengrong@iscas.ac.cn>
---
sysdeps/riscv/rvv/strrchr.S | 1 +
1 file changed, 1 insertion(+)
diff --git a/sysdeps/riscv/rvv/strrchr.S b/sysdeps/riscv/rvv/strrchr.S
index f2da8a4b..0ff856b3 100644
--- a/sysdeps/riscv/rvv/strrchr.S
+++ b/sysdeps/riscv/rvv/strrchr.S
@@ -49,6 +49,7 @@
ENTRY (STRRCHR)
.option push
.option arch, +v
+ andi ch, ch, 0xff
beqz ch, L(search_zero)
mv latest_ptr, zero
L(loop):
More information about the Libc-alpha
mailing list