[libc-commits] [libc] [libc] Expand usage of libc null checks. (PR #116262)

via libc-commits libc-commits at lists.llvm.org
Mon Jun 2 13:04:03 PDT 2025


================
@@ -9,11 +9,14 @@
 #include "src/string/memrchr.h"
 #include "src/__support/common.h"
 #include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
 #include <stddef.h>
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(void *, memrchr, (const void *src, int c, size_t n)) {
+  LIBC_CRASH_ON_NULLPTR(src);
----------------
lntue wrote:

These functions are probably GNU or BSD extensions and are not specified in the C standards, so technically we can define any behavior that we think it makes sense.  Nonetheless, the implementation below is not UB and well-behaved when `n = 0`, in addition to being consistent with `memchr`.

https://github.com/llvm/llvm-project/pull/116262


More information about the libc-commits mailing list