diff options
| author | Amir Ayupov <aaupov@fb.com> | 2025-06-08 17:43:02 -0700 |
|---|---|---|
| committer | Amir Ayupov <aaupov@fb.com> | 2025-06-08 17:43:02 -0700 |
| commit | 68b99df7ad1b910378c8cda5afff637fbe3c0efc (patch) | |
| tree | 1d2e51419c3f89a0909603d355598c27f1a92d42 /libc/test/src/string | |
| parent | bbbecc425389aeb7b93d9018b40a95b389c27f40 (diff) | |
| parent | c480dcddd91e3ff0707d6629e6ddac8587d9d1f1 (diff) | |
[𝘀𝗽𝗿] changes introduced through rebaseusers/aaupov/spr/main.bolt-sort-entrydata
Created using spr 1.3.4
[skip ci]
Diffstat (limited to 'libc/test/src/string')
| -rw-r--r-- | libc/test/src/string/memchr_test.cpp | 10 | ||||
| -rw-r--r-- | libc/test/src/string/memcmp_test.cpp | 10 | ||||
| -rw-r--r-- | libc/test/src/string/memcpy_test.cpp | 9 | ||||
| -rw-r--r-- | libc/test/src/string/memmove_test.cpp | 10 | ||||
| -rw-r--r-- | libc/test/src/string/mempcpy_test.cpp | 11 | ||||
| -rw-r--r-- | libc/test/src/string/memrchr_test.cpp | 10 | ||||
| -rw-r--r-- | libc/test/src/string/memset_test.cpp | 10 | ||||
| -rw-r--r-- | libc/test/src/string/stpncpy_test.cpp | 10 | ||||
| -rw-r--r-- | libc/test/src/string/strcat_test.cpp | 10 | ||||
| -rw-r--r-- | libc/test/src/string/strcoll_test.cpp | 10 | ||||
| -rw-r--r-- | libc/test/src/string/strcpy_test.cpp | 10 | ||||
| -rw-r--r-- | libc/test/src/string/strlcpy_test.cpp | 4 | ||||
| -rw-r--r-- | libc/test/src/string/strsep_test.cpp | 10 | ||||
| -rw-r--r-- | libc/test/src/string/strspn_test.cpp | 10 |
14 files changed, 131 insertions, 3 deletions
diff --git a/libc/test/src/string/memchr_test.cpp b/libc/test/src/string/memchr_test.cpp index 343958234edc..1455183e4646 100644 --- a/libc/test/src/string/memchr_test.cpp +++ b/libc/test/src/string/memchr_test.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "hdr/signal_macros.h" #include "src/string/memchr.h" #include "test/UnitTest/Test.h" #include <stddef.h> @@ -120,3 +121,12 @@ TEST(LlvmLibcMemChrTest, SignedCharacterFound) { // Should find the first character 'c'. ASSERT_EQ(actual[0], c); } + +#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) + +TEST(LlvmLibcMemChrTest, CrashOnNullPtr) { + ASSERT_DEATH([]() { LIBC_NAMESPACE::memchr(nullptr, 1, 1); }, + WITH_SIGNAL(-1)); +} + +#endif // defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) diff --git a/libc/test/src/string/memcmp_test.cpp b/libc/test/src/string/memcmp_test.cpp index 9f85a6d4f222..3dfbceda5953 100644 --- a/libc/test/src/string/memcmp_test.cpp +++ b/libc/test/src/string/memcmp_test.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "hdr/signal_macros.h" #include "memory_utils/memory_check_utils.h" #include "src/__support/macros/config.h" #include "src/string/memcmp.h" @@ -65,4 +66,13 @@ TEST(LlvmLibcMemcmpTest, SizeSweep) { } } +#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) + +TEST(LlvmLibcMemcmpTest, CrashOnNullPtr) { + ASSERT_DEATH([]() { LIBC_NAMESPACE::memcmp(nullptr, nullptr, 1); }, + WITH_SIGNAL(-1)); +} + +#endif // defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) + } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/test/src/string/memcpy_test.cpp b/libc/test/src/string/memcpy_test.cpp index ce267d17591f..8c43ac8b0e60 100644 --- a/libc/test/src/string/memcpy_test.cpp +++ b/libc/test/src/string/memcpy_test.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "hdr/signal_macros.h" #include "memory_utils/memory_check_utils.h" #include "src/__support/macros/config.h" #include "src/__support/macros/properties/os.h" // LIBC_TARGET_OS_IS_LINUX @@ -72,4 +73,12 @@ TEST(LlvmLibcMemcpyTest, CheckAccess) { #endif // !defined(LIBC_FULL_BUILD) && defined(LIBC_TARGET_OS_IS_LINUX) +#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) + +TEST(LlvmLibcMemcpyTest, CrashOnNullPtr) { + ASSERT_DEATH([]() { LIBC_NAMESPACE::memcpy(nullptr, nullptr, 1); }, + WITH_SIGNAL(-1)); +} +#endif // defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) + } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/test/src/string/memmove_test.cpp b/libc/test/src/string/memmove_test.cpp index 1e225e58ca1e..0d476555333d 100644 --- a/libc/test/src/string/memmove_test.cpp +++ b/libc/test/src/string/memmove_test.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "hdr/signal_macros.h" #include "src/__support/macros/config.h" #include "src/string/memmove.h" @@ -103,4 +104,13 @@ TEST(LlvmLibcMemmoveTest, SizeSweep) { } } +#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) + +TEST(LlvmLibcMemmoveTest, CrashOnNullPtr) { + ASSERT_DEATH([]() { LIBC_NAMESPACE::memmove(nullptr, nullptr, 2); }, + WITH_SIGNAL(-1)); +} + +#endif // LIBC_TARGET_OS_IS_LINUX + } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/test/src/string/mempcpy_test.cpp b/libc/test/src/string/mempcpy_test.cpp index 877ee8104880..24482a81352c 100644 --- a/libc/test/src/string/mempcpy_test.cpp +++ b/libc/test/src/string/mempcpy_test.cpp @@ -5,7 +5,7 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// - +#include "hdr/signal_macros.h" #include "src/string/mempcpy.h" #include "test/UnitTest/Test.h" @@ -26,3 +26,12 @@ TEST(LlvmLibcMempcpyTest, ZeroCount) { void *result = LIBC_NAMESPACE::mempcpy(dest, src, 0); ASSERT_EQ(static_cast<char *>(result), dest + 0); } + +#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) + +TEST(LlvmLibcMempcpyTest, CrashOnNullPtr) { + ASSERT_DEATH([]() { LIBC_NAMESPACE::mempcpy(nullptr, nullptr, 1); }, + WITH_SIGNAL(-1)); +} + +#endif // defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) diff --git a/libc/test/src/string/memrchr_test.cpp b/libc/test/src/string/memrchr_test.cpp index 421cb9b98516..c73a47917dd5 100644 --- a/libc/test/src/string/memrchr_test.cpp +++ b/libc/test/src/string/memrchr_test.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "hdr/signal_macros.h" #include "src/string/memrchr.h" #include "test/UnitTest/Test.h" #include <stddef.h> @@ -112,3 +113,12 @@ TEST(LlvmLibcMemRChrTest, ZeroLengthShouldReturnNullptr) { // This will iterate over exactly zero characters, so should return nullptr. ASSERT_STREQ(call_memrchr(src, 'd', 0), nullptr); } + +#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) + +TEST(LlvmLibcMemRChrTest, CrashOnNullPtr) { + ASSERT_DEATH([]() { LIBC_NAMESPACE::memrchr(nullptr, 'd', 1); }, + WITH_SIGNAL(-1)); +} + +#endif // defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) diff --git a/libc/test/src/string/memset_test.cpp b/libc/test/src/string/memset_test.cpp index 46d6ce747877..9562d2d2e37a 100644 --- a/libc/test/src/string/memset_test.cpp +++ b/libc/test/src/string/memset_test.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "hdr/signal_macros.h" #include "memory_utils/memory_check_utils.h" #include "src/__support/macros/config.h" #include "src/__support/macros/properties/os.h" // LIBC_TARGET_OS_IS_LINUX @@ -59,4 +60,13 @@ TEST(LlvmLibcMemsetTest, CheckAccess) { #endif // !defined(LIBC_FULL_BUILD) && defined(LIBC_TARGET_OS_IS_LINUX) +#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) + +TEST(LlvmLibcMemsetTest, CrashOnNullPtr) { + ASSERT_DEATH([]() { LIBC_NAMESPACE::memset(nullptr, 0, 1); }, + WITH_SIGNAL(-1)); +} + +#endif // defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) + } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/test/src/string/stpncpy_test.cpp b/libc/test/src/string/stpncpy_test.cpp index 247fa92a0c7b..f5c61e277f66 100644 --- a/libc/test/src/string/stpncpy_test.cpp +++ b/libc/test/src/string/stpncpy_test.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "hdr/signal_macros.h" #include "src/__support/CPP/span.h" #include "src/string/stpncpy.h" #include "test/UnitTest/Test.h" @@ -71,3 +72,12 @@ TEST_F(LlvmLibcStpncpyTest, CopyTwoWithNull) { const char expected[] = {'x', '\0'}; check_stpncpy(dst, src, 2, expected, 1); } + +#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) + +TEST_F(LlvmLibcStpncpyTest, CrashOnNullPtr) { + ASSERT_DEATH([]() { LIBC_NAMESPACE::stpncpy(nullptr, nullptr, 1); }, + WITH_SIGNAL(-1)); +} + +#endif // defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) diff --git a/libc/test/src/string/strcat_test.cpp b/libc/test/src/string/strcat_test.cpp index e4f6c1ee7599..20f8d11d239b 100644 --- a/libc/test/src/string/strcat_test.cpp +++ b/libc/test/src/string/strcat_test.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "hdr/signal_macros.h" #include "src/string/strcat.h" #include "test/UnitTest/Test.h" @@ -35,3 +36,12 @@ TEST(LlvmLibcStrCatTest, NonEmptyDest) { ASSERT_STREQ(dest, result); ASSERT_STREQ(dest, "xyzabc"); } + +#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) + +TEST(LlvmLibcStrCatTest, CrashOnNullPtr) { + ASSERT_DEATH([]() { LIBC_NAMESPACE::strcat(nullptr, nullptr); }, + WITH_SIGNAL(-1)); +} + +#endif // defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) diff --git a/libc/test/src/string/strcoll_test.cpp b/libc/test/src/string/strcoll_test.cpp index a10f98f1ca4d..268e232a9a98 100644 --- a/libc/test/src/string/strcoll_test.cpp +++ b/libc/test/src/string/strcoll_test.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "hdr/signal_macros.h" #include "src/string/strcoll.h" #include "test/UnitTest/Test.h" @@ -28,3 +29,12 @@ TEST(LlvmLibcStrcollTest, SimpleTest) { result = LIBC_NAMESPACE::strcoll(s3, s1); ASSERT_GT(result, 0); } + +#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) + +TEST(LlvmLibcStrcollTest, CrashOnNullPtr) { + ASSERT_DEATH([]() { LIBC_NAMESPACE::strcoll(nullptr, nullptr); }, + WITH_SIGNAL(-1)); +} + +#endif // defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) diff --git a/libc/test/src/string/strcpy_test.cpp b/libc/test/src/string/strcpy_test.cpp index 1a1227aac5d2..ead60be1267d 100644 --- a/libc/test/src/string/strcpy_test.cpp +++ b/libc/test/src/string/strcpy_test.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "hdr/signal_macros.h" #include "src/string/strcpy.h" #include "test/UnitTest/Test.h" @@ -42,3 +43,12 @@ TEST(LlvmLibcStrCpyTest, OffsetDest) { ASSERT_STREQ(dest + 3, result); ASSERT_STREQ(dest, "xyzabc"); } + +#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) + +TEST(LlvmLibcStrCpyTest, CrashOnNullPtr) { + ASSERT_DEATH([]() { LIBC_NAMESPACE::strcpy(nullptr, nullptr); }, + WITH_SIGNAL(-1)); +} + +#endif // defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) diff --git a/libc/test/src/string/strlcpy_test.cpp b/libc/test/src/string/strlcpy_test.cpp index 0914257ecc1f..b42954ca6137 100644 --- a/libc/test/src/string/strlcpy_test.cpp +++ b/libc/test/src/string/strlcpy_test.cpp @@ -14,8 +14,8 @@ TEST(LlvmLibcStrlcpyTest, TooBig) { char buf[2]; EXPECT_EQ(LIBC_NAMESPACE::strlcpy(buf, str, 2), size_t(3)); EXPECT_STREQ(buf, "a"); - - EXPECT_EQ(LIBC_NAMESPACE::strlcpy(nullptr, str, 0), size_t(3)); + char dst[] = ""; + EXPECT_EQ(LIBC_NAMESPACE::strlcpy(dst, str, 0), size_t(3)); } TEST(LlvmLibcStrlcpyTest, Smaller) { diff --git a/libc/test/src/string/strsep_test.cpp b/libc/test/src/string/strsep_test.cpp index 0daa29f6a7ad..6f02ce36edf2 100644 --- a/libc/test/src/string/strsep_test.cpp +++ b/libc/test/src/string/strsep_test.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "hdr/signal_macros.h" #include "src/string/strsep.h" #include "test/UnitTest/Test.h" @@ -51,3 +52,12 @@ TEST(LlvmLibcStrsepTest, DelimitersShouldNotBeIncludedInToken) { ASSERT_STREQ(LIBC_NAMESPACE::strsep(&string, "_:"), expected[i]); } } + +#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) + +TEST(LlvmLibcStrsepTest, CrashOnNullPtr) { + ASSERT_DEATH([]() { LIBC_NAMESPACE::strsep(nullptr, nullptr); }, + WITH_SIGNAL(-1)); +} + +#endif // defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) diff --git a/libc/test/src/string/strspn_test.cpp b/libc/test/src/string/strspn_test.cpp index cdd12af07ee7..adf9a4564a1f 100644 --- a/libc/test/src/string/strspn_test.cpp +++ b/libc/test/src/string/strspn_test.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "hdr/signal_macros.h" #include "src/string/strspn.h" #include "test/UnitTest/Test.h" @@ -83,3 +84,12 @@ TEST(LlvmLibcStrSpnTest, DuplicatedCharactersToBeSearchedForShouldStillMatch) { EXPECT_EQ(LIBC_NAMESPACE::strspn("aaa", "aa"), size_t{3}); EXPECT_EQ(LIBC_NAMESPACE::strspn("aaaa", "aa"), size_t{4}); } + +#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) + +TEST(LlvmLibcStrSpnTest, CrashOnNullPtr) { + ASSERT_DEATH([]() { LIBC_NAMESPACE::strspn(nullptr, nullptr); }, + WITH_SIGNAL(-1)); +} + +#endif // defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) |
