From 8ed72e7c1caa0eb4238e649063c26a11720935de Mon Sep 17 00:00:00 2001 From: jvoisin Date: Tue, 19 Mar 2024 18:35:13 +0100 Subject: Relax our checks for memchr on C11 and above Since C11: > This function behaves as if it reads the bytes sequentially and stops as soon as a matching bytes is found: if the array pointed to by ptr is smaller than count, but the match is found within the array, the behavior is well-defined. Reported-by: q66 --- include/string.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/string.h b/include/string.h index 24c1501..db2e6c3 100644 --- a/include/string.h +++ b/include/string.h @@ -123,10 +123,12 @@ _FORTIFY_FN(memchr) void *memchr(const void * _FORTIFY_POS0 __d, int __c, size_t if (!__d) __builtin_trap(); +#if __STDC_VERSION__ < 201112L __fh_size_t __b = __fh_bos(__d, 0); - if (__n > __b) __builtin_trap(); +#endif + return __builtin_memchr(__d, __c, __n); #endif } -- cgit v1.3