summaryrefslogtreecommitdiff
path: root/libc/src/string/memchr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libc/src/string/memchr.cpp')
-rw-r--r--libc/src/string/memchr.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/libc/src/string/memchr.cpp b/libc/src/string/memchr.cpp
index ba52f14afa9d..ccdc262837cd 100644
--- a/libc/src/string/memchr.cpp
+++ b/libc/src/string/memchr.cpp
@@ -8,6 +8,7 @@
#include "src/string/memchr.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
#include "src/string/string_utils.h"
#include "src/__support/common.h"
@@ -17,6 +18,8 @@ namespace LIBC_NAMESPACE_DECL {
// TODO: Look at performance benefits of comparing words.
LLVM_LIBC_FUNCTION(void *, memchr, (const void *src, int c, size_t n)) {
+ if (n)
+ LIBC_CRASH_ON_NULLPTR(src);
return internal::find_first_character(
reinterpret_cast<const unsigned char *>(src),
static_cast<unsigned char>(c), n);