summaryrefslogtreecommitdiffstats
path: root/newlib/libc
diff options
context:
space:
mode:
Diffstat (limited to 'newlib/libc')
-rw-r--r--newlib/libc/machine/aarch64/memchr.S6
1 files changed, 6 insertions, 0 deletions
diff --git a/newlib/libc/machine/aarch64/memchr.S b/newlib/libc/machine/aarch64/memchr.S
index eb59a5aad..53f5d6bc0 100644
--- a/newlib/libc/machine/aarch64/memchr.S
+++ b/newlib/libc/machine/aarch64/memchr.S
@@ -79,6 +79,8 @@
.endm
def_fn memchr
+ /* Do not dereference srcin if no bytes to compare. */
+ cbz cntin, .Lzero_length
/*
* Magic constant 0x40100401 allows us to identify which lane matches
* the requested byte.
@@ -166,5 +168,9 @@ def_fn memchr
csel result, xzr, result, eq
ret
+.Lzero_length:
+ mov result, #0
+ ret
+
.size memchr, . - memchr
#endif