summaryrefslogtreecommitdiff
path: root/libc/src/string/strncmp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libc/src/string/strncmp.cpp')
-rw-r--r--libc/src/string/strncmp.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/libc/src/string/strncmp.cpp b/libc/src/string/strncmp.cpp
index 16d4601fe845..f21fd769f394 100644
--- a/libc/src/string/strncmp.cpp
+++ b/libc/src/string/strncmp.cpp
@@ -10,6 +10,7 @@
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
#include "src/string/memory_utils/inline_strcmp.h"
#include <stddef.h>
@@ -18,6 +19,10 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, strncmp,
(const char *left, const char *right, size_t n)) {
+ if (n) {
+ LIBC_CRASH_ON_NULLPTR(left);
+ LIBC_CRASH_ON_NULLPTR(right);
+ }
auto comp = [](char l, char r) -> int { return l - r; };
return inline_strncmp(left, right, n, comp);
}