Hi,
On 29/5/26 04:38, Bin Guo wrote:
qemu_strnlen() uses a byte-at-a-time loop with an XXX TODO
comment noting that the host strnlen() could be used instead.
strnlen() is POSIX.1-2008 and is available on all platforms QEMU
supports (guaranteed by qemu/osdep.h).
If so, there are only 3 uses in the code base. Maybe drop
qemu_strnlen() altogether, using size_t in the callers?
The host C library
implementation typically uses word-at-a-time or SIMD scanning,
which is significantly faster for long strings.
Replace the loop with a direct call to strnlen(). Add an explicit
cast from size_t to int since qemu_strnlen() returns int while
strnlen() returns size_t; the cast is safe because max_len (the
upper bound on the return value) is already int.
Signed-off-by: Bin Guo <[email protected]>
---
util/cutils.c | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)