summaryrefslogtreecommitdiff
path: root/include/string.h
diff options
context:
space:
mode:
authorjvoisin2024-03-19 18:35:13 +0100
committerjvoisin2024-03-19 18:35:13 +0100
commit8ed72e7c1caa0eb4238e649063c26a11720935de (patch)
tree24e478a8ebdb9e69eefcea193781a39bc22c21c0 /include/string.h
parent140cffbe84a08669d67c3257258d2bb70ff29c3b (diff)
Relax our checks for memchr on C11 and above2.2
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
Diffstat (limited to 'include/string.h')
-rw-r--r--include/string.h4
1 files changed, 3 insertions, 1 deletions
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
123 if (!__d) 123 if (!__d)
124 __builtin_trap(); 124 __builtin_trap();
125 125
126#if __STDC_VERSION__ < 201112L
126 __fh_size_t __b = __fh_bos(__d, 0); 127 __fh_size_t __b = __fh_bos(__d, 0);
127
128 if (__n > __b) 128 if (__n > __b)
129 __builtin_trap(); 129 __builtin_trap();
130#endif
131
130 return __builtin_memchr(__d, __c, __n); 132 return __builtin_memchr(__d, __c, __n);
131#endif 133#endif
132} 134}