[libc-commits] [libc] [libc] Expand usage of libc null checks. (PR #116262)
via libc-commits
libc-commits at lists.llvm.org
Thu May 1 07:20:22 PDT 2025
================
@@ -120,3 +121,12 @@ TEST(LlvmLibcMemChrTest, SignedCharacterFound) {
// Should find the first character 'c'.
ASSERT_EQ(actual[0], c);
}
+
+#ifdef LIBC_TARGET_OS_IS_LINUX
+
+TEST(LlvmLibcMemChrTest, CrashOnNullPtr) {
+ ASSERT_DEATH([]() { LIBC_NAMESPACE::memchr(nullptr, 1, 1); },
+ WITH_SIGNAL(SIGILL));
+}
+
+#endif // defined(LIBC_TARGET_OS_IS_LINUX)
----------------
lntue wrote:
Extra guards are needed for this, because depending on the build config, `LIBC_CRASH_ON_NULLPTR` can simply be no-op, and in those cases, anything can happen.
These tests should be similar to https://github.com/llvm/llvm-project/blob/main/libc/test/src/math/smoke/nanf_test.cpp#L46
https://github.com/llvm/llvm-project/pull/116262
More information about the libc-commits
mailing list