[libc-commits] [libc] [libc] Expand usage of libc null checks. (PR #116262)
Aly ElAshram via libc-commits
libc-commits at lists.llvm.org
Sun Jan 26 06:45:15 PST 2025
https://github.com/AlyElashram updated https://github.com/llvm/llvm-project/pull/116262
>From 8af2807b8663555f30679e61b9fc65de4b9b3f9a Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Mon, 11 Nov 2024 20:18:21 +0200
Subject: [PATCH 01/35] Add NullChecks to fflush.cpp
---
libc/src/stdio/generic/fflush.cpp | 3 +++
libc/src/stdio/gpu/fflush.cpp | 3 +++
2 files changed, 6 insertions(+)
diff --git a/libc/src/stdio/generic/fflush.cpp b/libc/src/stdio/generic/fflush.cpp
index 5bdf71ad359406..8c71fbbd3d0999 100644
--- a/libc/src/stdio/generic/fflush.cpp
+++ b/libc/src/stdio/generic/fflush.cpp
@@ -11,11 +11,14 @@
#include "hdr/types/FILE.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
#include "src/errno/libc_errno.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, fflush, (::FILE * stream)) {
+
+ LIBC_CRASH_ON_NULLPTR(stream);
int result = reinterpret_cast<LIBC_NAMESPACE::File *>(stream)->flush();
if (result != 0) {
libc_errno = result;
diff --git a/libc/src/stdio/gpu/fflush.cpp b/libc/src/stdio/gpu/fflush.cpp
index 5a5137be6a4af0..47843f4d08093b 100644
--- a/libc/src/stdio/gpu/fflush.cpp
+++ b/libc/src/stdio/gpu/fflush.cpp
@@ -9,12 +9,15 @@
#include "src/stdio/fflush.h"
#include "file.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
#include "hdr/types/FILE.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, fflush, (::FILE * stream)) {
+
+ LIBC_CRASH_ON_NULLPTR(stream);
int ret;
rpc::Client::Port port = rpc::client.open<LIBC_FFLUSH>();
port.send_and_recv(
>From fa4be6f5a7b422cca91bb2821e25d7d8314b4924 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Mon, 11 Nov 2024 20:26:43 +0200
Subject: [PATCH 02/35] Add NullChecks to fopen.cpp
---
libc/src/stdio/generic/fopen.cpp | 3 +++
libc/src/stdio/gpu/fopen.cpp | 3 +++
2 files changed, 6 insertions(+)
diff --git a/libc/src/stdio/generic/fopen.cpp b/libc/src/stdio/generic/fopen.cpp
index d6e418bacf37e4..91219cb722cf59 100644
--- a/libc/src/stdio/generic/fopen.cpp
+++ b/libc/src/stdio/generic/fopen.cpp
@@ -11,12 +11,15 @@
#include "hdr/types/FILE.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
#include "src/errno/libc_errno.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(::FILE *, fopen,
(const char *__restrict name, const char *__restrict mode)) {
+ LIBC_CRASH_ON_NULLPTR(name);
+ LIBC_CRASH_ON_NULLPTR(mode);
auto result = LIBC_NAMESPACE::openfile(name, mode);
if (!result.has_value()) {
libc_errno = result.error();
diff --git a/libc/src/stdio/gpu/fopen.cpp b/libc/src/stdio/gpu/fopen.cpp
index 18dd7195377893..dfba587de18f31 100644
--- a/libc/src/stdio/gpu/fopen.cpp
+++ b/libc/src/stdio/gpu/fopen.cpp
@@ -9,6 +9,7 @@
#include "src/stdio/fopen.h"
#include "src/__support/CPP/string_view.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
#include "src/stdio/gpu/file.h"
#include "hdr/types/FILE.h"
@@ -17,6 +18,8 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(::FILE *, fopen,
(const char *__restrict path, const char *__restrict mode)) {
+ LIBC_CRASH_ON_NULLPTR(path);
+ LIBC_CRASH_ON_NULLPTR(mode);
uintptr_t file;
rpc::Client::Port port = rpc::client.open<LIBC_OPEN_FILE>();
port.send_n(path, internal::string_length(path) + 1);
>From a2e7bc6c8be51c8d7357776a80f3f7e94ac0c7a5 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Mon, 11 Nov 2024 20:36:34 +0200
Subject: [PATCH 03/35] Add NullChecks to fprintf.cpp
---
libc/src/stdio/generic/fprintf.cpp | 3 +++
libc/src/stdio/gpu/fprintf.cpp | 3 +++
2 files changed, 6 insertions(+)
diff --git a/libc/src/stdio/generic/fprintf.cpp b/libc/src/stdio/generic/fprintf.cpp
index 087aeadfc52c5c..478093355f3cd0 100644
--- a/libc/src/stdio/generic/fprintf.cpp
+++ b/libc/src/stdio/generic/fprintf.cpp
@@ -11,6 +11,7 @@
#include "src/__support/File/file.h"
#include "src/__support/arg_list.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
#include "src/stdio/printf_core/vfprintf_internal.h"
#include "hdr/types/FILE.h"
@@ -21,6 +22,8 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, fprintf,
(::FILE *__restrict stream, const char *__restrict format,
...)) {
+ LIBC_CRASH_ON_NULLPTR(stream);
+ LIBC_CRASH_ON_NULLPTR(format);
va_list vlist;
va_start(vlist, format);
internal::ArgList args(vlist); // This holder class allows for easier copying
diff --git a/libc/src/stdio/gpu/fprintf.cpp b/libc/src/stdio/gpu/fprintf.cpp
index 46196d7d2b10f5..3273277be1c585 100644
--- a/libc/src/stdio/gpu/fprintf.cpp
+++ b/libc/src/stdio/gpu/fprintf.cpp
@@ -11,6 +11,7 @@
#include "hdr/types/FILE.h"
#include "src/__support/CPP/string_view.h"
#include "src/__support/arg_list.h"
+#include "src/__support/macros/null_check.h"
#include "src/errno/libc_errno.h"
#include "src/stdio/gpu/vfprintf_utils.h"
@@ -21,6 +22,8 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, fprintf,
(::FILE *__restrict stream, const char *__restrict format,
...)) {
+ LIBC_CRASH_ON_NULLPTR(stream);
+ LIBC_CRASH_ON_NULLPTR(format);
va_list vlist;
va_start(vlist, format);
cpp::string_view str_view(format);
>From 684b15f90b0b5aa6c8753c3c35482e2dc2e8ed5b Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Thu, 14 Nov 2024 00:57:22 +0200
Subject: [PATCH 04/35] Add NullChecks to fscanf.cpp
---
libc/src/stdio/fscanf.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/libc/src/stdio/fscanf.cpp b/libc/src/stdio/fscanf.cpp
index 94b843978749e2..c79c92671b659f 100644
--- a/libc/src/stdio/fscanf.cpp
+++ b/libc/src/stdio/fscanf.cpp
@@ -11,6 +11,7 @@
#include "src/__support/File/file.h"
#include "src/__support/arg_list.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
#include "src/stdio/scanf_core/vfscanf_internal.h"
#include "hdr/types/FILE.h"
@@ -21,6 +22,8 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, fscanf,
(::FILE *__restrict stream, const char *__restrict format,
...)) {
+ LIBC_CRASH_ON_NULLPTR(stream);
+ LIBC_CRASH_ON_NULLPTR(format);
va_list vlist;
va_start(vlist, format);
internal::ArgList args(vlist); // This holder class allows for easier copying
>From 1ae6db51f6dbe3b07a8203aaf8a404979688556e Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Thu, 14 Nov 2024 18:40:11 +0200
Subject: [PATCH 05/35] Add NullChecks to vprintf.cpp
---
libc/src/stdio/baremetal/vprintf.cpp | 2 ++
libc/src/stdio/generic/vprintf.cpp | 2 ++
libc/src/stdio/gpu/vprintf.cpp | 2 ++
3 files changed, 6 insertions(+)
diff --git a/libc/src/stdio/baremetal/vprintf.cpp b/libc/src/stdio/baremetal/vprintf.cpp
index 617b5f488e7728..c80f6052efea3a 100644
--- a/libc/src/stdio/baremetal/vprintf.cpp
+++ b/libc/src/stdio/baremetal/vprintf.cpp
@@ -10,6 +10,7 @@
#include "src/__support/OSUtil/io.h"
#include "src/__support/arg_list.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
#include "src/stdio/printf_core/core_structs.h"
#include "src/stdio/printf_core/printf_main.h"
#include "src/stdio/printf_core/writer.h"
@@ -30,6 +31,7 @@ LIBC_INLINE int raw_write_hook(cpp::string_view new_str, void *) {
LLVM_LIBC_FUNCTION(int, vprintf,
(const char *__restrict format, va_list vlist)) {
+ LIBC_CRASH_ON_NULLPTR(format);
internal::ArgList args(vlist); // This holder class allows for easier copying
// and pointer semantics, as well as handling
// destruction automatically.
diff --git a/libc/src/stdio/generic/vprintf.cpp b/libc/src/stdio/generic/vprintf.cpp
index 08d71515646ed0..6c51ba31319980 100644
--- a/libc/src/stdio/generic/vprintf.cpp
+++ b/libc/src/stdio/generic/vprintf.cpp
@@ -11,6 +11,7 @@
#include "src/__support/File/file.h"
#include "src/__support/arg_list.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
#include "src/stdio/printf_core/vfprintf_internal.h"
#include "hdr/types/FILE.h"
@@ -26,6 +27,7 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, vprintf,
(const char *__restrict format, va_list vlist)) {
+ LIBC_CRASH_ON_NULLPTR(format);
internal::ArgList args(vlist); // This holder class allows for easier copying
// and pointer semantics, as well as handling
// destruction automatically.
diff --git a/libc/src/stdio/gpu/vprintf.cpp b/libc/src/stdio/gpu/vprintf.cpp
index 54012f3071844d..49391aa4f3f127 100644
--- a/libc/src/stdio/gpu/vprintf.cpp
+++ b/libc/src/stdio/gpu/vprintf.cpp
@@ -10,6 +10,7 @@
#include "src/__support/CPP/string_view.h"
#include "src/__support/arg_list.h"
+#include "src/__support/macros/null_check.h"
#include "src/errno/libc_errno.h"
#include "src/stdio/gpu/vfprintf_utils.h"
@@ -17,6 +18,7 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, vprintf,
(const char *__restrict format, va_list vlist)) {
+ LIBC_CRASH_ON_NULLPTR(format);
cpp::string_view str_view(format);
int ret_val = vfprintf_internal(stdout, format, str_view.size() + 1, vlist);
return ret_val;
>From e7e539f59f58bb8e1b911331ce792c7424b589af Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 13 Dec 2024 18:16:36 +0200
Subject: [PATCH 06/35] Add NullChecks to memory_utils
---
libc/src/string/memory_utils/inline_strcmp.h | 5 +++++
libc/src/string/memory_utils/inline_strstr.h | 3 +++
2 files changed, 8 insertions(+)
diff --git a/libc/src/string/memory_utils/inline_strcmp.h b/libc/src/string/memory_utils/inline_strcmp.h
index 281d5b14c6cbac..db0bba909a539a 100644
--- a/libc/src/string/memory_utils/inline_strcmp.h
+++ b/libc/src/string/memory_utils/inline_strcmp.h
@@ -10,6 +10,7 @@
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_STRCMP_H
#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
#include <stddef.h>
namespace LIBC_NAMESPACE_DECL {
@@ -17,6 +18,8 @@ namespace LIBC_NAMESPACE_DECL {
template <typename Comp>
LIBC_INLINE constexpr int inline_strcmp(const char *left, const char *right,
Comp &&comp) {
+ LIBC_CRASH_ON_NULLPTR(left);
+ LIBC_CRASH_ON_NULLPTR(right);
// TODO: Look at benefits for comparing words at a time.
for (; *left && !comp(*left, *right); ++left, ++right)
;
@@ -27,6 +30,8 @@ LIBC_INLINE constexpr int inline_strcmp(const char *left, const char *right,
template <typename Comp>
LIBC_INLINE constexpr int inline_strncmp(const char *left, const char *right,
size_t n, Comp &&comp) {
+ LIBC_CRASH_ON_NULLPTR(left);
+ LIBC_CRASH_ON_NULLPTR(right);
if (n == 0)
return 0;
diff --git a/libc/src/string/memory_utils/inline_strstr.h b/libc/src/string/memory_utils/inline_strstr.h
index 9c99e920b4b570..8b00f8565376c3 100644
--- a/libc/src/string/memory_utils/inline_strstr.h
+++ b/libc/src/string/memory_utils/inline_strstr.h
@@ -10,6 +10,7 @@
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_STRSTR_H
#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
#include "src/string/memory_utils/inline_memmem.h"
#include "src/string/string_utils.h"
#include <stddef.h>
@@ -19,6 +20,8 @@ namespace LIBC_NAMESPACE_DECL {
template <typename Comp>
LIBC_INLINE constexpr char *inline_strstr(const char *haystack,
const char *needle, Comp &&comp) {
+ LIBC_CRASH_ON_NULLPTR(haystack);
+ LIBC_CRASH_ON_NULLPTR(needle);
void *result = inline_memmem(
static_cast<const void *>(haystack), internal::string_length(haystack),
static_cast<const void *>(needle), internal::string_length(needle), comp);
>From b8f853bece10b0b3e63bff232af3fbea1712afa5 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 13 Dec 2024 18:17:13 +0200
Subject: [PATCH 07/35] Add NullChecks to memchr.cpp
---
libc/src/string/memchr.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/libc/src/string/memchr.cpp b/libc/src/string/memchr.cpp
index ba52f14afa9d65..dcc5ee99bbe545 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,7 @@ 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)) {
+ LIBC_CRASH_ON_NULLPTR(src);
return internal::find_first_character(
reinterpret_cast<const unsigned char *>(src),
static_cast<unsigned char>(c), n);
>From b896655f7de06ea2cd7f6df5c5c3fa42e02af726 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 13 Dec 2024 18:17:20 +0200
Subject: [PATCH 08/35] Add NullChecks to memcmp.cpp
---
libc/src/string/memcmp.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/libc/src/string/memcmp.cpp b/libc/src/string/memcmp.cpp
index 68996fb7872368..71c6840d14ca83 100644
--- a/libc/src/string/memcmp.cpp
+++ b/libc/src/string/memcmp.cpp
@@ -8,6 +8,7 @@
#include "src/string/memcmp.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
#include "src/string/memory_utils/inline_memcmp.h"
#include <stddef.h> // size_t
@@ -16,6 +17,8 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, memcmp,
(const void *lhs, const void *rhs, size_t count)) {
+ LIBC_CRASH_ON_NULLPTR(lhs);
+ LIBC_CRASH_ON_NULLPTR(rhs);
return inline_memcmp(lhs, rhs, count);
}
>From b1894eb60c3b875c998a74fe42e1c6c973a07bfa Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 13 Dec 2024 18:17:27 +0200
Subject: [PATCH 09/35] Add NullChecks to memcpy.cpp
---
libc/src/string/memcpy.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/libc/src/string/memcpy.cpp b/libc/src/string/memcpy.cpp
index 0eb7f2c170e085..9f0406d08d6456 100644
--- a/libc/src/string/memcpy.cpp
+++ b/libc/src/string/memcpy.cpp
@@ -9,6 +9,7 @@
#include "src/string/memcpy.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
#include "src/string/memory_utils/inline_memcpy.h"
namespace LIBC_NAMESPACE_DECL {
@@ -16,6 +17,8 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(void *, memcpy,
(void *__restrict dst, const void *__restrict src,
size_t size)) {
+ LIBC_CRASH_ON_NULLPTR(dst);
+ LIBC_CRASH_ON_NULLPTR(src);
inline_memcpy(dst, src, size);
return dst;
}
>From 4893e61309f5471ebd5b518913fe0d2db7e434ed Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 13 Dec 2024 18:17:37 +0200
Subject: [PATCH 10/35] Add NullChecks to memmove.cpp
---
libc/src/string/memmove.cpp | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/libc/src/string/memmove.cpp b/libc/src/string/memmove.cpp
index 26a8c4187f3d31..ca77795cc16474 100644
--- a/libc/src/string/memmove.cpp
+++ b/libc/src/string/memmove.cpp
@@ -8,6 +8,7 @@
#include "src/string/memmove.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
#include "src/string/memory_utils/inline_memcpy.h"
#include "src/string/memory_utils/inline_memmove.h"
#include <stddef.h> // size_t
@@ -16,6 +17,9 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(void *, memmove,
(void *dst, const void *src, size_t count)) {
+ LIBC_CRASH_ON_NULLPTR(dst);
+ LIBC_CRASH_ON_NULLPTR(src);
+
// Memmove may handle some small sizes as efficiently as inline_memcpy.
// For these sizes we may not do is_disjoint check.
// This both avoids additional code for the most frequent smaller sizes
>From e3e4ac6871d7eb46e7eb266330f7ca70a4ae472d Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 13 Dec 2024 18:17:47 +0200
Subject: [PATCH 11/35] Add NullChecks to mempcpy.cpp
---
libc/src/string/mempcpy.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/libc/src/string/mempcpy.cpp b/libc/src/string/mempcpy.cpp
index 09392ceb966d6b..a7b5c7efbadb72 100644
--- a/libc/src/string/mempcpy.cpp
+++ b/libc/src/string/mempcpy.cpp
@@ -8,6 +8,7 @@
#include "src/string/mempcpy.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
#include "src/string/memory_utils/inline_memcpy.h"
#include "src/__support/common.h"
@@ -18,6 +19,8 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(void *, mempcpy,
(void *__restrict dst, const void *__restrict src,
size_t count)) {
+ LIBC_CRASH_ON_NULLPTR(dst);
+ LIBC_CRASH_ON_NULLPTR(src);
inline_memcpy(dst, src, count);
return reinterpret_cast<char *>(dst) + count;
}
>From 8a8714b0049f16230527e79a566b687bc006344c Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 13 Dec 2024 18:17:52 +0200
Subject: [PATCH 12/35] Add NullChecks to memrchr.cpp
---
libc/src/string/memrchr.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/libc/src/string/memrchr.cpp b/libc/src/string/memrchr.cpp
index d665e225bbb7dd..319bec97ae7177 100644
--- a/libc/src/string/memrchr.cpp
+++ b/libc/src/string/memrchr.cpp
@@ -9,11 +9,13 @@
#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);
const unsigned char *str = reinterpret_cast<const unsigned char *>(src);
const unsigned char ch = static_cast<unsigned char>(c);
for (; n != 0; --n) {
>From 49706e2458cd06b9dd12b43b544bce0df3df7aaa Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 13 Dec 2024 18:17:57 +0200
Subject: [PATCH 13/35] Add NullChecks to memset.cpp
---
libc/src/string/memset.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/libc/src/string/memset.cpp b/libc/src/string/memset.cpp
index c2868afa91031d..53448af9d97945 100644
--- a/libc/src/string/memset.cpp
+++ b/libc/src/string/memset.cpp
@@ -9,11 +9,13 @@
#include "src/string/memset.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
#include "src/string/memory_utils/inline_memset.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(void *, memset, (void *dst, int value, size_t count)) {
+ LIBC_CRASH_ON_NULLPTR(dst);
inline_memset(dst, static_cast<uint8_t>(value), count);
return dst;
}
>From 8d5b1385c3981617fb0598c66a635f55d9d0ac31 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 13 Dec 2024 18:18:04 +0200
Subject: [PATCH 14/35] Add NullChecks to rindex.cpp
---
libc/src/strings/rindex.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/libc/src/strings/rindex.cpp b/libc/src/strings/rindex.cpp
index 1242e0faf85fc5..2540222ffb0eb6 100644
--- a/libc/src/strings/rindex.cpp
+++ b/libc/src/strings/rindex.cpp
@@ -10,11 +10,13 @@
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
#include "src/string/string_utils.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(char *, rindex, (const char *src, int c)) {
+ LIBC_CRASH_ON_NULLPTR(src);
return internal::strrchr_implementation(src, c);
}
>From c08fea7f33c54adc4ccced2950ddf48ed71b844c Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 13 Dec 2024 18:18:09 +0200
Subject: [PATCH 15/35] Add NullChecks to stpncpy.cpp
---
libc/src/string/stpncpy.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/libc/src/string/stpncpy.cpp b/libc/src/string/stpncpy.cpp
index d2a6e04749820e..b545b5de777d21 100644
--- a/libc/src/string/stpncpy.cpp
+++ b/libc/src/string/stpncpy.cpp
@@ -8,6 +8,7 @@
#include "src/string/stpncpy.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
#include "src/string/memory_utils/inline_bzero.h"
#include "src/__support/common.h"
@@ -17,6 +18,8 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(char *, stpncpy,
(char *__restrict dest, const char *__restrict src,
size_t n)) {
+ LIBC_CRASH_ON_NULLPTR(dest);
+ LIBC_CRASH_ON_NULLPTR(src);
size_t i;
// Copy up until \0 is found.
for (i = 0; i < n && src[i] != '\0'; ++i)
>From e80329d55abb5b0a3f8ca224b5f7702f3fd0db4e Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 13 Dec 2024 18:18:14 +0200
Subject: [PATCH 16/35] Add NullChecks to strcat.cpp
---
libc/src/string/strcat.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/libc/src/string/strcat.cpp b/libc/src/string/strcat.cpp
index 0eb189ce204f0c..6a6f068bd47594 100644
--- a/libc/src/string/strcat.cpp
+++ b/libc/src/string/strcat.cpp
@@ -8,6 +8,7 @@
#include "src/string/strcat.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
#include "src/string/strcpy.h"
#include "src/string/string_utils.h"
@@ -17,6 +18,8 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(char *, strcat,
(char *__restrict dest, const char *__restrict src)) {
+ LIBC_CRASH_ON_NULLPTR(dest);
+ LIBC_CRASH_ON_NULLPTR(src);
size_t dest_length = internal::string_length(dest);
size_t src_length = internal::string_length(src);
LIBC_NAMESPACE::strcpy(dest + dest_length, src);
>From 4339a2f3319a42504b54ee1f8e3527c7ffb25e23 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 13 Dec 2024 18:18:30 +0200
Subject: [PATCH 17/35] Add NullChecks to strcoll.cpp and strcoll_l.cpp
---
libc/src/string/strcoll.cpp | 3 +++
libc/src/string/strcoll_l.cpp | 3 +++
2 files changed, 6 insertions(+)
diff --git a/libc/src/string/strcoll.cpp b/libc/src/string/strcoll.cpp
index eeb2c79e380742..aa08f7194c9e52 100644
--- a/libc/src/string/strcoll.cpp
+++ b/libc/src/string/strcoll.cpp
@@ -10,11 +10,14 @@
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
namespace LIBC_NAMESPACE_DECL {
// TODO: Add support for locales.
LLVM_LIBC_FUNCTION(int, strcoll, (const char *left, const char *right)) {
+ LIBC_CRASH_ON_NULLPTR(left);
+ LIBC_CRASH_ON_NULLPTR(right);
for (; *left && *left == *right; ++left, ++right)
;
return static_cast<int>(*left) - static_cast<int>(*right);
diff --git a/libc/src/string/strcoll_l.cpp b/libc/src/string/strcoll_l.cpp
index f664a3c7c03f37..e820efa564a3db 100644
--- a/libc/src/string/strcoll_l.cpp
+++ b/libc/src/string/strcoll_l.cpp
@@ -10,12 +10,15 @@
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
namespace LIBC_NAMESPACE_DECL {
// TODO: Add support for locales.
LLVM_LIBC_FUNCTION(int, strcoll_l,
(const char *left, const char *right, locale_t)) {
+ LIBC_CRASH_ON_NULLPTR(left);
+ LIBC_CRASH_ON_NULLPTR(right);
for (; *left && *left == *right; ++left, ++right)
;
return static_cast<int>(*left) - static_cast<int>(*right);
>From 53cffe6fb514dab8710f5f84a96cb2666580a617 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 13 Dec 2024 18:18:41 +0200
Subject: [PATCH 18/35] Add NullChecks to strcpy and strncpy
---
libc/src/string/strcpy.cpp | 2 ++
libc/src/string/strncpy.cpp | 3 +++
2 files changed, 5 insertions(+)
diff --git a/libc/src/string/strcpy.cpp b/libc/src/string/strcpy.cpp
index 60b73ab3aa823f..2013593db24a6e 100644
--- a/libc/src/string/strcpy.cpp
+++ b/libc/src/string/strcpy.cpp
@@ -8,6 +8,7 @@
#include "src/string/strcpy.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
#include "src/string/memory_utils/inline_memcpy.h"
#include "src/string/string_utils.h"
@@ -17,6 +18,7 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(char *, strcpy,
(char *__restrict dest, const char *__restrict src)) {
+ LIBC_CRASH_ON_NULLPTR(dest);
size_t size = internal::string_length(src) + 1;
inline_memcpy(dest, src, size);
return dest;
diff --git a/libc/src/string/strncpy.cpp b/libc/src/string/strncpy.cpp
index 4976ad94708c71..303ec4f44880e1 100644
--- a/libc/src/string/strncpy.cpp
+++ b/libc/src/string/strncpy.cpp
@@ -10,6 +10,7 @@
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
#include <stddef.h> // For size_t.
namespace LIBC_NAMESPACE_DECL {
@@ -17,6 +18,8 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(char *, strncpy,
(char *__restrict dest, const char *__restrict src,
size_t n)) {
+ LIBC_CRASH_ON_NULLPTR(dest);
+ LIBC_CRASH_ON_NULLPTR(src);
size_t i = 0;
// Copy up until \0 is found.
for (; i < n && src[i] != '\0'; ++i)
>From ba039d322fb2abd15a6a5d4a8fae2fde8f7792df Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 13 Dec 2024 18:18:51 +0200
Subject: [PATCH 19/35] Add NullChecks to strsep.cpp
---
libc/src/string/strsep.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/libc/src/string/strsep.cpp b/libc/src/string/strsep.cpp
index 4c275122de52fc..976fefe1008bc2 100644
--- a/libc/src/string/strsep.cpp
+++ b/libc/src/string/strsep.cpp
@@ -9,6 +9,7 @@
#include "src/string/strsep.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
#include "src/string/string_utils.h"
namespace LIBC_NAMESPACE_DECL {
@@ -17,6 +18,7 @@ LLVM_LIBC_FUNCTION(char *, strsep,
(char **__restrict stringp, const char *__restrict delim)) {
if (!*stringp)
return nullptr;
+ LIBC_CRASH_ON_NULLPTR(delim);
return internal::string_token<false>(*stringp, delim, stringp);
}
>From 73070dcc2dff53a924e6870a6eb82978657172f8 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 13 Dec 2024 18:18:59 +0200
Subject: [PATCH 20/35] Add NullChecks to strspn.cpp
---
libc/src/string/strspn.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/libc/src/string/strspn.cpp b/libc/src/string/strspn.cpp
index 66bb39903ab382..b205bedf80caba 100644
--- a/libc/src/string/strspn.cpp
+++ b/libc/src/string/strspn.cpp
@@ -11,11 +11,14 @@
#include "src/__support/CPP/bitset.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(size_t, strspn, (const char *src, const char *segment)) {
+ LIBC_CRASH_ON_NULLPTR(src);
+ LIBC_CRASH_ON_NULLPTR(segment);
const char *initial = src;
cpp::bitset<256> bitset;
>From 63e78a4129ba2c4ebc34b500000ee90e9941dffc Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 13 Dec 2024 22:06:27 +0200
Subject: [PATCH 21/35] Revert "Add NullChecks to vprintf.cpp"
This reverts commit 26f370f14e264d98d2845ccfc214a2891d1fe240.
---
libc/src/stdio/baremetal/vprintf.cpp | 2 --
libc/src/stdio/generic/vprintf.cpp | 2 --
libc/src/stdio/gpu/vprintf.cpp | 2 --
3 files changed, 6 deletions(-)
diff --git a/libc/src/stdio/baremetal/vprintf.cpp b/libc/src/stdio/baremetal/vprintf.cpp
index c80f6052efea3a..617b5f488e7728 100644
--- a/libc/src/stdio/baremetal/vprintf.cpp
+++ b/libc/src/stdio/baremetal/vprintf.cpp
@@ -10,7 +10,6 @@
#include "src/__support/OSUtil/io.h"
#include "src/__support/arg_list.h"
#include "src/__support/macros/config.h"
-#include "src/__support/macros/null_check.h"
#include "src/stdio/printf_core/core_structs.h"
#include "src/stdio/printf_core/printf_main.h"
#include "src/stdio/printf_core/writer.h"
@@ -31,7 +30,6 @@ LIBC_INLINE int raw_write_hook(cpp::string_view new_str, void *) {
LLVM_LIBC_FUNCTION(int, vprintf,
(const char *__restrict format, va_list vlist)) {
- LIBC_CRASH_ON_NULLPTR(format);
internal::ArgList args(vlist); // This holder class allows for easier copying
// and pointer semantics, as well as handling
// destruction automatically.
diff --git a/libc/src/stdio/generic/vprintf.cpp b/libc/src/stdio/generic/vprintf.cpp
index 6c51ba31319980..08d71515646ed0 100644
--- a/libc/src/stdio/generic/vprintf.cpp
+++ b/libc/src/stdio/generic/vprintf.cpp
@@ -11,7 +11,6 @@
#include "src/__support/File/file.h"
#include "src/__support/arg_list.h"
#include "src/__support/macros/config.h"
-#include "src/__support/macros/null_check.h"
#include "src/stdio/printf_core/vfprintf_internal.h"
#include "hdr/types/FILE.h"
@@ -27,7 +26,6 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, vprintf,
(const char *__restrict format, va_list vlist)) {
- LIBC_CRASH_ON_NULLPTR(format);
internal::ArgList args(vlist); // This holder class allows for easier copying
// and pointer semantics, as well as handling
// destruction automatically.
diff --git a/libc/src/stdio/gpu/vprintf.cpp b/libc/src/stdio/gpu/vprintf.cpp
index 49391aa4f3f127..54012f3071844d 100644
--- a/libc/src/stdio/gpu/vprintf.cpp
+++ b/libc/src/stdio/gpu/vprintf.cpp
@@ -10,7 +10,6 @@
#include "src/__support/CPP/string_view.h"
#include "src/__support/arg_list.h"
-#include "src/__support/macros/null_check.h"
#include "src/errno/libc_errno.h"
#include "src/stdio/gpu/vfprintf_utils.h"
@@ -18,7 +17,6 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, vprintf,
(const char *__restrict format, va_list vlist)) {
- LIBC_CRASH_ON_NULLPTR(format);
cpp::string_view str_view(format);
int ret_val = vfprintf_internal(stdout, format, str_view.size() + 1, vlist);
return ret_val;
>From 295e6e9880f929145fed767455f2d3c0313f3cdc Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 13 Dec 2024 22:06:35 +0200
Subject: [PATCH 22/35] Revert "Add NullChecks to fscanf.cpp"
This reverts commit 043ed9eea917589c83b80186b9b68f8aeaf4fea0.
---
libc/src/stdio/fscanf.cpp | 3 ---
1 file changed, 3 deletions(-)
diff --git a/libc/src/stdio/fscanf.cpp b/libc/src/stdio/fscanf.cpp
index c79c92671b659f..94b843978749e2 100644
--- a/libc/src/stdio/fscanf.cpp
+++ b/libc/src/stdio/fscanf.cpp
@@ -11,7 +11,6 @@
#include "src/__support/File/file.h"
#include "src/__support/arg_list.h"
#include "src/__support/macros/config.h"
-#include "src/__support/macros/null_check.h"
#include "src/stdio/scanf_core/vfscanf_internal.h"
#include "hdr/types/FILE.h"
@@ -22,8 +21,6 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, fscanf,
(::FILE *__restrict stream, const char *__restrict format,
...)) {
- LIBC_CRASH_ON_NULLPTR(stream);
- LIBC_CRASH_ON_NULLPTR(format);
va_list vlist;
va_start(vlist, format);
internal::ArgList args(vlist); // This holder class allows for easier copying
>From 488a61735dcdf3fa6b37c29bcb8c0ab29be1b26a Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 13 Dec 2024 22:06:35 +0200
Subject: [PATCH 23/35] Revert "Add NullChecks to fprintf.cpp"
This reverts commit b8e48a9bf302704018150ea021a5a65152bcb712.
---
libc/src/stdio/generic/fprintf.cpp | 3 ---
libc/src/stdio/gpu/fprintf.cpp | 3 ---
2 files changed, 6 deletions(-)
diff --git a/libc/src/stdio/generic/fprintf.cpp b/libc/src/stdio/generic/fprintf.cpp
index 478093355f3cd0..087aeadfc52c5c 100644
--- a/libc/src/stdio/generic/fprintf.cpp
+++ b/libc/src/stdio/generic/fprintf.cpp
@@ -11,7 +11,6 @@
#include "src/__support/File/file.h"
#include "src/__support/arg_list.h"
#include "src/__support/macros/config.h"
-#include "src/__support/macros/null_check.h"
#include "src/stdio/printf_core/vfprintf_internal.h"
#include "hdr/types/FILE.h"
@@ -22,8 +21,6 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, fprintf,
(::FILE *__restrict stream, const char *__restrict format,
...)) {
- LIBC_CRASH_ON_NULLPTR(stream);
- LIBC_CRASH_ON_NULLPTR(format);
va_list vlist;
va_start(vlist, format);
internal::ArgList args(vlist); // This holder class allows for easier copying
diff --git a/libc/src/stdio/gpu/fprintf.cpp b/libc/src/stdio/gpu/fprintf.cpp
index 3273277be1c585..46196d7d2b10f5 100644
--- a/libc/src/stdio/gpu/fprintf.cpp
+++ b/libc/src/stdio/gpu/fprintf.cpp
@@ -11,7 +11,6 @@
#include "hdr/types/FILE.h"
#include "src/__support/CPP/string_view.h"
#include "src/__support/arg_list.h"
-#include "src/__support/macros/null_check.h"
#include "src/errno/libc_errno.h"
#include "src/stdio/gpu/vfprintf_utils.h"
@@ -22,8 +21,6 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, fprintf,
(::FILE *__restrict stream, const char *__restrict format,
...)) {
- LIBC_CRASH_ON_NULLPTR(stream);
- LIBC_CRASH_ON_NULLPTR(format);
va_list vlist;
va_start(vlist, format);
cpp::string_view str_view(format);
>From e2da16cc6acda46fd6fa4a4e0681e9342fe74cd9 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 13 Dec 2024 22:06:35 +0200
Subject: [PATCH 24/35] Revert "Add NullChecks to fopen.cpp"
This reverts commit 2829d8769aa816fa61c8f0ae59056f0577c90cc0.
---
libc/src/stdio/generic/fopen.cpp | 3 ---
libc/src/stdio/gpu/fopen.cpp | 3 ---
2 files changed, 6 deletions(-)
diff --git a/libc/src/stdio/generic/fopen.cpp b/libc/src/stdio/generic/fopen.cpp
index 91219cb722cf59..d6e418bacf37e4 100644
--- a/libc/src/stdio/generic/fopen.cpp
+++ b/libc/src/stdio/generic/fopen.cpp
@@ -11,15 +11,12 @@
#include "hdr/types/FILE.h"
#include "src/__support/macros/config.h"
-#include "src/__support/macros/null_check.h"
#include "src/errno/libc_errno.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(::FILE *, fopen,
(const char *__restrict name, const char *__restrict mode)) {
- LIBC_CRASH_ON_NULLPTR(name);
- LIBC_CRASH_ON_NULLPTR(mode);
auto result = LIBC_NAMESPACE::openfile(name, mode);
if (!result.has_value()) {
libc_errno = result.error();
diff --git a/libc/src/stdio/gpu/fopen.cpp b/libc/src/stdio/gpu/fopen.cpp
index dfba587de18f31..18dd7195377893 100644
--- a/libc/src/stdio/gpu/fopen.cpp
+++ b/libc/src/stdio/gpu/fopen.cpp
@@ -9,7 +9,6 @@
#include "src/stdio/fopen.h"
#include "src/__support/CPP/string_view.h"
#include "src/__support/macros/config.h"
-#include "src/__support/macros/null_check.h"
#include "src/stdio/gpu/file.h"
#include "hdr/types/FILE.h"
@@ -18,8 +17,6 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(::FILE *, fopen,
(const char *__restrict path, const char *__restrict mode)) {
- LIBC_CRASH_ON_NULLPTR(path);
- LIBC_CRASH_ON_NULLPTR(mode);
uintptr_t file;
rpc::Client::Port port = rpc::client.open<LIBC_OPEN_FILE>();
port.send_n(path, internal::string_length(path) + 1);
>From 9bbb0172eacd69595cde96b879da0f52ae74972a Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 13 Dec 2024 22:06:35 +0200
Subject: [PATCH 25/35] Revert "Add NullChecks to fflush.cpp"
This reverts commit 9b75c8abd38b14e1d8c90cc571d3d323f75903f4.
---
libc/src/stdio/generic/fflush.cpp | 3 ---
libc/src/stdio/gpu/fflush.cpp | 3 ---
2 files changed, 6 deletions(-)
diff --git a/libc/src/stdio/generic/fflush.cpp b/libc/src/stdio/generic/fflush.cpp
index 8c71fbbd3d0999..5bdf71ad359406 100644
--- a/libc/src/stdio/generic/fflush.cpp
+++ b/libc/src/stdio/generic/fflush.cpp
@@ -11,14 +11,11 @@
#include "hdr/types/FILE.h"
#include "src/__support/macros/config.h"
-#include "src/__support/macros/null_check.h"
#include "src/errno/libc_errno.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, fflush, (::FILE * stream)) {
-
- LIBC_CRASH_ON_NULLPTR(stream);
int result = reinterpret_cast<LIBC_NAMESPACE::File *>(stream)->flush();
if (result != 0) {
libc_errno = result;
diff --git a/libc/src/stdio/gpu/fflush.cpp b/libc/src/stdio/gpu/fflush.cpp
index 47843f4d08093b..5a5137be6a4af0 100644
--- a/libc/src/stdio/gpu/fflush.cpp
+++ b/libc/src/stdio/gpu/fflush.cpp
@@ -9,15 +9,12 @@
#include "src/stdio/fflush.h"
#include "file.h"
#include "src/__support/macros/config.h"
-#include "src/__support/macros/null_check.h"
#include "hdr/types/FILE.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, fflush, (::FILE * stream)) {
-
- LIBC_CRASH_ON_NULLPTR(stream);
int ret;
rpc::Client::Port port = rpc::client.open<LIBC_FFLUSH>();
port.send_and_recv(
>From aea12f728a4d5ff6a6f5b5ce2677613d3f975158 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 13 Dec 2024 22:54:25 +0200
Subject: [PATCH 26/35] Modify NullChecks to cast pointers as it will fail
dereferencing a nullptr
---
libc/src/string/memchr.cpp | 3 ++-
libc/src/string/memcmp.cpp | 6 ++++--
libc/src/string/memcpy.cpp | 6 ++++--
libc/src/string/memmove.cpp | 6 ++++--
libc/src/string/mempcpy.cpp | 6 ++++--
libc/src/string/memrchr.cpp | 4 +++-
libc/src/string/memset.cpp | 3 ++-
7 files changed, 23 insertions(+), 11 deletions(-)
diff --git a/libc/src/string/memchr.cpp b/libc/src/string/memchr.cpp
index dcc5ee99bbe545..d69b80a4f8bd44 100644
--- a/libc/src/string/memchr.cpp
+++ b/libc/src/string/memchr.cpp
@@ -18,7 +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)) {
- LIBC_CRASH_ON_NULLPTR(src);
+ const unsigned char *src_cpy = (const unsigned char *)src;
+ LIBC_CRASH_ON_NULLPTR(src_cpy);
return internal::find_first_character(
reinterpret_cast<const unsigned char *>(src),
static_cast<unsigned char>(c), n);
diff --git a/libc/src/string/memcmp.cpp b/libc/src/string/memcmp.cpp
index 71c6840d14ca83..82a1126a558f27 100644
--- a/libc/src/string/memcmp.cpp
+++ b/libc/src/string/memcmp.cpp
@@ -17,8 +17,10 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, memcmp,
(const void *lhs, const void *rhs, size_t count)) {
- LIBC_CRASH_ON_NULLPTR(lhs);
- LIBC_CRASH_ON_NULLPTR(rhs);
+ const unsigned char *left = (const unsigned char *)lhs;
+ const unsigned char *right = (const unsigned char *)rhs;
+ LIBC_CRASH_ON_NULLPTR(left);
+ LIBC_CRASH_ON_NULLPTR(right);
return inline_memcmp(lhs, rhs, count);
}
diff --git a/libc/src/string/memcpy.cpp b/libc/src/string/memcpy.cpp
index 9f0406d08d6456..712443a6a5c040 100644
--- a/libc/src/string/memcpy.cpp
+++ b/libc/src/string/memcpy.cpp
@@ -17,8 +17,10 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(void *, memcpy,
(void *__restrict dst, const void *__restrict src,
size_t size)) {
- LIBC_CRASH_ON_NULLPTR(dst);
- LIBC_CRASH_ON_NULLPTR(src);
+ const unsigned char *dst_cpy = (const unsigned char *)dst;
+ const unsigned char *src_cpy = (const unsigned char *)src;
+ LIBC_CRASH_ON_NULLPTR(dst_cpy);
+ LIBC_CRASH_ON_NULLPTR(src_cpy);
inline_memcpy(dst, src, size);
return dst;
}
diff --git a/libc/src/string/memmove.cpp b/libc/src/string/memmove.cpp
index ca77795cc16474..3ef020253ec31b 100644
--- a/libc/src/string/memmove.cpp
+++ b/libc/src/string/memmove.cpp
@@ -17,8 +17,10 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(void *, memmove,
(void *dst, const void *src, size_t count)) {
- LIBC_CRASH_ON_NULLPTR(dst);
- LIBC_CRASH_ON_NULLPTR(src);
+ const unsigned char *dst_cpy = (const unsigned char *)dst;
+ const unsigned char *src_cpy = (const unsigned char *)src;
+ LIBC_CRASH_ON_NULLPTR(dst_cpy);
+ LIBC_CRASH_ON_NULLPTR(src_cpy);
// Memmove may handle some small sizes as efficiently as inline_memcpy.
// For these sizes we may not do is_disjoint check.
diff --git a/libc/src/string/mempcpy.cpp b/libc/src/string/mempcpy.cpp
index a7b5c7efbadb72..c6d4c027df749a 100644
--- a/libc/src/string/mempcpy.cpp
+++ b/libc/src/string/mempcpy.cpp
@@ -19,8 +19,10 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(void *, mempcpy,
(void *__restrict dst, const void *__restrict src,
size_t count)) {
- LIBC_CRASH_ON_NULLPTR(dst);
- LIBC_CRASH_ON_NULLPTR(src);
+ const unsigned char *dst_cpy = (const unsigned char *)dst;
+ const unsigned char *src_cpy = (const unsigned char *)src;
+ LIBC_CRASH_ON_NULLPTR(dst_cpy);
+ LIBC_CRASH_ON_NULLPTR(src_cpy);
inline_memcpy(dst, src, count);
return reinterpret_cast<char *>(dst) + count;
}
diff --git a/libc/src/string/memrchr.cpp b/libc/src/string/memrchr.cpp
index 319bec97ae7177..6e7e05d0773472 100644
--- a/libc/src/string/memrchr.cpp
+++ b/libc/src/string/memrchr.cpp
@@ -15,7 +15,9 @@
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(void *, memrchr, (const void *src, int c, size_t n)) {
- LIBC_CRASH_ON_NULLPTR(src);
+ const unsigned char *src_cpy = (const unsigned char *)src;
+ LIBC_CRASH_ON_NULLPTR(src_cpy);
+
const unsigned char *str = reinterpret_cast<const unsigned char *>(src);
const unsigned char ch = static_cast<unsigned char>(c);
for (; n != 0; --n) {
diff --git a/libc/src/string/memset.cpp b/libc/src/string/memset.cpp
index 53448af9d97945..2af587bcfcbee6 100644
--- a/libc/src/string/memset.cpp
+++ b/libc/src/string/memset.cpp
@@ -15,7 +15,8 @@
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(void *, memset, (void *dst, int value, size_t count)) {
- LIBC_CRASH_ON_NULLPTR(dst);
+ const unsigned char *dst_cpy = (const unsigned char *)dst;
+ LIBC_CRASH_ON_NULLPTR(dst_cpy);
inline_memset(dst, static_cast<uint8_t>(value), count);
return dst;
}
>From cc24429b8e177754dbdc8e32fc7f3286182d95f0 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Sun, 22 Dec 2024 22:28:45 +0200
Subject: [PATCH 27/35] Modify Unit Tests to include crashing on nullptrs
---
libc/test/src/string/CMakeLists.txt | 9 +++++++++
libc/test/src/string/memchr_test.cpp | 5 +++++
libc/test/src/string/memcmp_test.cpp | 5 +++++
libc/test/src/string/memcpy_test.cpp | 5 +++++
libc/test/src/string/mempcpy_test.cpp | 6 +++++-
libc/test/src/string/memrchr_test.cpp | 5 +++++
libc/test/src/string/stpncpy_test.cpp | 4 ++++
libc/test/src/string/strcat_test.cpp | 5 +++++
libc/test/src/string/strcoll_test.cpp | 4 ++++
libc/test/src/string/strcpy_test.cpp | 5 +++++
libc/test/src/string/strlcpy_test.cpp | 4 ++--
libc/test/src/string/strsep_test.cpp | 4 ++++
libc/test/src/string/strspn_test.cpp | 5 +++++
13 files changed, 63 insertions(+), 3 deletions(-)
diff --git a/libc/test/src/string/CMakeLists.txt b/libc/test/src/string/CMakeLists.txt
index a675373938e996..109ef3e4da6a2c 100644
--- a/libc/test/src/string/CMakeLists.txt
+++ b/libc/test/src/string/CMakeLists.txt
@@ -20,6 +20,7 @@ add_libc_test(
add_libc_test(
mempcpy_test
+ UNIT_TEST_ONLY
SUITE
libc-string-tests
SRCS
@@ -40,6 +41,7 @@ add_libc_test(
add_libc_test(
memchr_test
+ UNIT_TEST_ONLY
SUITE
libc-string-tests
SRCS
@@ -50,6 +52,7 @@ add_libc_test(
add_libc_test(
memrchr_test
+ UNIT_TEST_ONLY
SUITE
libc-string-tests
SRCS
@@ -70,6 +73,7 @@ add_libc_test(
add_libc_test(
stpncpy_test
+ UNIT_TEST_ONLY
SUITE
libc-string-tests
SRCS
@@ -80,6 +84,7 @@ add_libc_test(
add_libc_test(
strcat_test
+ UNIT_TEST_ONLY
SUITE
libc-string-tests
SRCS
@@ -131,6 +136,7 @@ add_libc_test(
add_libc_test(
strcoll_test
+ UNIT_TEST_ONLY
SUITE
libc-string-tests
SRCS
@@ -141,6 +147,7 @@ add_libc_test(
add_libc_test(
strcpy_test
+ UNIT_TEST_ONLY
SUITE
libc-string-tests
SRCS
@@ -296,6 +303,7 @@ add_libc_test(
add_libc_test(
strsep_test
+ UNIT_TEST_ONLY
SUITE
libc-string-tests
SRCS
@@ -316,6 +324,7 @@ add_libc_test(
add_libc_test(
strspn_test
+ UNIT_TEST_ONLY
SUITE
libc-string-tests
SRCS
diff --git a/libc/test/src/string/memchr_test.cpp b/libc/test/src/string/memchr_test.cpp
index 343958234edcee..bcf895c9276479 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,7 @@ TEST(LlvmLibcMemChrTest, SignedCharacterFound) {
// Should find the first character 'c'.
ASSERT_EQ(actual[0], c);
}
+
+TEST(LlvmLibcMemChrTest, CrashOnNullPtr) {
+ ASSERT_DEATH([](){ LIBC_NAMESPACE::memchr(nullptr, 1, 1); } , WITH_SIGNAL(SIGSEGV));
+}
\ No newline at end of file
diff --git a/libc/test/src/string/memcmp_test.cpp b/libc/test/src/string/memcmp_test.cpp
index 9f85a6d4f2229a..00118cedb92200 100644
--- a/libc/test/src/string/memcmp_test.cpp
+++ b/libc/test/src/string/memcmp_test.cpp
@@ -65,4 +65,9 @@ TEST(LlvmLibcMemcmpTest, SizeSweep) {
}
}
+#include "hdr/signal_macros.h"
+TEST(LlvmLibcMemcmpTest, CrashOnNullPtr) {
+ ASSERT_DEATH([](){ LIBC_NAMESPACE::memcmp(nullptr, 1, 1); } , WITH_SIGNAL(SIGSEGV));
+}
+
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/string/memcpy_test.cpp b/libc/test/src/string/memcpy_test.cpp
index adf6ef7e66d3f2..e30fd9687d1790 100644
--- a/libc/test/src/string/memcpy_test.cpp
+++ b/libc/test/src/string/memcpy_test.cpp
@@ -72,4 +72,9 @@ TEST(LlvmLibcMemcpyTest, CheckAccess) {
#endif // !defined(LIBC_FULL_BUILD) && defined(LIBC_TARGET_OS_IS_LINUX)
+#include "hdr/signal_macros.h"
+TEST(LlvmLibcMemcpyTest, CrashOnNullPtr) {
+ ASSERT_DEATH(LIBC_NAMESPACE::memcpy(nullptr, nullptr, 1), WITH_SIGNAL(SIGSEGV));
+}
+
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/string/mempcpy_test.cpp b/libc/test/src/string/mempcpy_test.cpp
index 877ee8104880eb..32097589d41118 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,7 @@ TEST(LlvmLibcMempcpyTest, ZeroCount) {
void *result = LIBC_NAMESPACE::mempcpy(dest, src, 0);
ASSERT_EQ(static_cast<char *>(result), dest + 0);
}
+
+TEST(LlvmLibcMempcpyTest, CrashOnNullPtr) {
+ ASSERT_DEATH([](){ LIBC_NAMESPACE::mempcpy(nullptr, nullptr, 0); } , WITH_SIGNAL(SIGSEGV));
+}
\ No newline at end of file
diff --git a/libc/test/src/string/memrchr_test.cpp b/libc/test/src/string/memrchr_test.cpp
index 421cb9b98516e5..d07b751effbce8 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,7 @@ TEST(LlvmLibcMemRChrTest, ZeroLengthShouldReturnNullptr) {
// This will iterate over exactly zero characters, so should return nullptr.
ASSERT_STREQ(call_memrchr(src, 'd', 0), nullptr);
}
+
+TEST(LlvmLibcMemRChrTest, CrashOnNullPtr) {
+ ASSERT_DEATH([](){ LIBC_NAMESPACE::memrchr(nullptr, 'd', 1); } , WITH_SIGNAL(SIGSEGV));
+}
diff --git a/libc/test/src/string/stpncpy_test.cpp b/libc/test/src/string/stpncpy_test.cpp
index 247fa92a0c7bfa..2b0bc3519849e2 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,6 @@ TEST_F(LlvmLibcStpncpyTest, CopyTwoWithNull) {
const char expected[] = {'x', '\0'};
check_stpncpy(dst, src, 2, expected, 1);
}
+TEST_F(LlvmLibcStpncpyTest, CrashOnNullPtr) {
+ ASSERT_DEATH( [](){LIBC_NAMESPACE::stpncpy(nullptr, nullptr, 1);} , WITH_SIGNAL(SIGSEGV));
+}
diff --git a/libc/test/src/string/strcat_test.cpp b/libc/test/src/string/strcat_test.cpp
index e4f6c1ee75992e..0e77ba12a8cd90 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,7 @@ TEST(LlvmLibcStrCatTest, NonEmptyDest) {
ASSERT_STREQ(dest, result);
ASSERT_STREQ(dest, "xyzabc");
}
+
+TEST(LlvmLibcStrCatTest, CrashOnNullPtr) {
+ ASSERT_DEATH( [](){LIBC_NAMESPACE::strcat(nullptr, nullptr);} , WITH_SIGNAL(SIGSEGV));
+}
\ No newline at end of file
diff --git a/libc/test/src/string/strcoll_test.cpp b/libc/test/src/string/strcoll_test.cpp
index a10f98f1ca4d6a..ee501fa7eeee18 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,6 @@ TEST(LlvmLibcStrcollTest, SimpleTest) {
result = LIBC_NAMESPACE::strcoll(s3, s1);
ASSERT_GT(result, 0);
}
+TEST(LlvmLibcStrcollTest, CrashOnNullPtr) {
+ ASSERT_DEATH( [](){LIBC_NAMESPACE::strcoll(nullptr, nullptr);} , WITH_SIGNAL(SIGSEGV));
+}
diff --git a/libc/test/src/string/strcpy_test.cpp b/libc/test/src/string/strcpy_test.cpp
index 1a1227aac5d2f8..a0b7c6bd9e1ac2 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,7 @@ TEST(LlvmLibcStrCpyTest, OffsetDest) {
ASSERT_STREQ(dest + 3, result);
ASSERT_STREQ(dest, "xyzabc");
}
+
+TEST(LlvmLibcStrCpyTest, CrashOnNullPtr) {
+ ASSERT_DEATH( [](){LIBC_NAMESPACE::strcpy(nullptr, nullptr); } , WITH_SIGNAL(SIGSEGV));
+}
diff --git a/libc/test/src/string/strlcpy_test.cpp b/libc/test/src/string/strlcpy_test.cpp
index 0914257ecc1f34..b42954ca6137aa 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 0daa29f6a7ad59..3aacf941a655f2 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,6 @@ TEST(LlvmLibcStrsepTest, DelimitersShouldNotBeIncludedInToken) {
ASSERT_STREQ(LIBC_NAMESPACE::strsep(&string, "_:"), expected[i]);
}
}
+TEST(LlvmLibcStrsepTest, CrashOnNullPtr) {
+ ASSERT_DEATH( [](){LIBC_NAMESPACE::strsep(nullptr, nullptr);} , WITH_SIGNAL(SIGSEGV));
+}
diff --git a/libc/test/src/string/strspn_test.cpp b/libc/test/src/string/strspn_test.cpp
index cdd12af07ee7da..c53d05e1db4d90 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,7 @@ TEST(LlvmLibcStrSpnTest, DuplicatedCharactersToBeSearchedForShouldStillMatch) {
EXPECT_EQ(LIBC_NAMESPACE::strspn("aaa", "aa"), size_t{3});
EXPECT_EQ(LIBC_NAMESPACE::strspn("aaaa", "aa"), size_t{4});
}
+
+TEST(LlvmLibcStrSpnTest, CrashOnNullPtr) {
+ ASSERT_DEATH([](){ LIBC_NAMESPACE::strspn(nullptr, nullptr); } , WITH_SIGNAL(SIGSEGV));
+}
\ No newline at end of file
>From 3e23d3952bf525787a2b391dcacc0e47a0df44f9 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Sun, 22 Dec 2024 22:28:57 +0200
Subject: [PATCH 28/35] Formatting
---
libc/test/src/string/memchr_test.cpp | 3 ++-
libc/test/src/string/memcmp_test.cpp | 3 ++-
libc/test/src/string/memcpy_test.cpp | 3 ++-
libc/test/src/string/mempcpy_test.cpp | 3 ++-
libc/test/src/string/memrchr_test.cpp | 3 ++-
libc/test/src/string/stpncpy_test.cpp | 3 ++-
libc/test/src/string/strcat_test.cpp | 3 ++-
libc/test/src/string/strcoll_test.cpp | 3 ++-
libc/test/src/string/strcpy_test.cpp | 3 ++-
libc/test/src/string/strsep_test.cpp | 3 ++-
libc/test/src/string/strspn_test.cpp | 3 ++-
11 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/libc/test/src/string/memchr_test.cpp b/libc/test/src/string/memchr_test.cpp
index bcf895c9276479..2950672d751846 100644
--- a/libc/test/src/string/memchr_test.cpp
+++ b/libc/test/src/string/memchr_test.cpp
@@ -123,5 +123,6 @@ TEST(LlvmLibcMemChrTest, SignedCharacterFound) {
}
TEST(LlvmLibcMemChrTest, CrashOnNullPtr) {
- ASSERT_DEATH([](){ LIBC_NAMESPACE::memchr(nullptr, 1, 1); } , WITH_SIGNAL(SIGSEGV));
+ ASSERT_DEATH([]() { LIBC_NAMESPACE::memchr(nullptr, 1, 1); },
+ WITH_SIGNAL(SIGSEGV));
}
\ No newline at end of file
diff --git a/libc/test/src/string/memcmp_test.cpp b/libc/test/src/string/memcmp_test.cpp
index 00118cedb92200..45180c18df0711 100644
--- a/libc/test/src/string/memcmp_test.cpp
+++ b/libc/test/src/string/memcmp_test.cpp
@@ -67,7 +67,8 @@ TEST(LlvmLibcMemcmpTest, SizeSweep) {
#include "hdr/signal_macros.h"
TEST(LlvmLibcMemcmpTest, CrashOnNullPtr) {
- ASSERT_DEATH([](){ LIBC_NAMESPACE::memcmp(nullptr, 1, 1); } , WITH_SIGNAL(SIGSEGV));
+ ASSERT_DEATH([]() { LIBC_NAMESPACE::memcmp(nullptr, 1, 1); },
+ WITH_SIGNAL(SIGSEGV));
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/string/memcpy_test.cpp b/libc/test/src/string/memcpy_test.cpp
index e30fd9687d1790..430252e39f013c 100644
--- a/libc/test/src/string/memcpy_test.cpp
+++ b/libc/test/src/string/memcpy_test.cpp
@@ -74,7 +74,8 @@ TEST(LlvmLibcMemcpyTest, CheckAccess) {
#include "hdr/signal_macros.h"
TEST(LlvmLibcMemcpyTest, CrashOnNullPtr) {
- ASSERT_DEATH(LIBC_NAMESPACE::memcpy(nullptr, nullptr, 1), WITH_SIGNAL(SIGSEGV));
+ ASSERT_DEATH(LIBC_NAMESPACE::memcpy(nullptr, nullptr, 1),
+ WITH_SIGNAL(SIGSEGV));
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/string/mempcpy_test.cpp b/libc/test/src/string/mempcpy_test.cpp
index 32097589d41118..af4a05444ec467 100644
--- a/libc/test/src/string/mempcpy_test.cpp
+++ b/libc/test/src/string/mempcpy_test.cpp
@@ -28,5 +28,6 @@ TEST(LlvmLibcMempcpyTest, ZeroCount) {
}
TEST(LlvmLibcMempcpyTest, CrashOnNullPtr) {
- ASSERT_DEATH([](){ LIBC_NAMESPACE::mempcpy(nullptr, nullptr, 0); } , WITH_SIGNAL(SIGSEGV));
+ ASSERT_DEATH([]() { LIBC_NAMESPACE::mempcpy(nullptr, nullptr, 0); },
+ WITH_SIGNAL(SIGSEGV));
}
\ No newline at end of file
diff --git a/libc/test/src/string/memrchr_test.cpp b/libc/test/src/string/memrchr_test.cpp
index d07b751effbce8..b138801bc27878 100644
--- a/libc/test/src/string/memrchr_test.cpp
+++ b/libc/test/src/string/memrchr_test.cpp
@@ -115,5 +115,6 @@ TEST(LlvmLibcMemRChrTest, ZeroLengthShouldReturnNullptr) {
}
TEST(LlvmLibcMemRChrTest, CrashOnNullPtr) {
- ASSERT_DEATH([](){ LIBC_NAMESPACE::memrchr(nullptr, 'd', 1); } , WITH_SIGNAL(SIGSEGV));
+ ASSERT_DEATH([]() { LIBC_NAMESPACE::memrchr(nullptr, 'd', 1); },
+ WITH_SIGNAL(SIGSEGV));
}
diff --git a/libc/test/src/string/stpncpy_test.cpp b/libc/test/src/string/stpncpy_test.cpp
index 2b0bc3519849e2..9f3a8292b5ca67 100644
--- a/libc/test/src/string/stpncpy_test.cpp
+++ b/libc/test/src/string/stpncpy_test.cpp
@@ -73,5 +73,6 @@ TEST_F(LlvmLibcStpncpyTest, CopyTwoWithNull) {
check_stpncpy(dst, src, 2, expected, 1);
}
TEST_F(LlvmLibcStpncpyTest, CrashOnNullPtr) {
- ASSERT_DEATH( [](){LIBC_NAMESPACE::stpncpy(nullptr, nullptr, 1);} , WITH_SIGNAL(SIGSEGV));
+ ASSERT_DEATH([]() { LIBC_NAMESPACE::stpncpy(nullptr, nullptr, 1); },
+ WITH_SIGNAL(SIGSEGV));
}
diff --git a/libc/test/src/string/strcat_test.cpp b/libc/test/src/string/strcat_test.cpp
index 0e77ba12a8cd90..9a0eb7a1645aba 100644
--- a/libc/test/src/string/strcat_test.cpp
+++ b/libc/test/src/string/strcat_test.cpp
@@ -38,5 +38,6 @@ TEST(LlvmLibcStrCatTest, NonEmptyDest) {
}
TEST(LlvmLibcStrCatTest, CrashOnNullPtr) {
- ASSERT_DEATH( [](){LIBC_NAMESPACE::strcat(nullptr, nullptr);} , WITH_SIGNAL(SIGSEGV));
+ ASSERT_DEATH([]() { LIBC_NAMESPACE::strcat(nullptr, nullptr); },
+ WITH_SIGNAL(SIGSEGV));
}
\ No newline at end of file
diff --git a/libc/test/src/string/strcoll_test.cpp b/libc/test/src/string/strcoll_test.cpp
index ee501fa7eeee18..b308bf1653059e 100644
--- a/libc/test/src/string/strcoll_test.cpp
+++ b/libc/test/src/string/strcoll_test.cpp
@@ -30,5 +30,6 @@ TEST(LlvmLibcStrcollTest, SimpleTest) {
ASSERT_GT(result, 0);
}
TEST(LlvmLibcStrcollTest, CrashOnNullPtr) {
- ASSERT_DEATH( [](){LIBC_NAMESPACE::strcoll(nullptr, nullptr);} , WITH_SIGNAL(SIGSEGV));
+ ASSERT_DEATH([]() { LIBC_NAMESPACE::strcoll(nullptr, nullptr); },
+ WITH_SIGNAL(SIGSEGV));
}
diff --git a/libc/test/src/string/strcpy_test.cpp b/libc/test/src/string/strcpy_test.cpp
index a0b7c6bd9e1ac2..f0c328c7342bd2 100644
--- a/libc/test/src/string/strcpy_test.cpp
+++ b/libc/test/src/string/strcpy_test.cpp
@@ -45,5 +45,6 @@ TEST(LlvmLibcStrCpyTest, OffsetDest) {
}
TEST(LlvmLibcStrCpyTest, CrashOnNullPtr) {
- ASSERT_DEATH( [](){LIBC_NAMESPACE::strcpy(nullptr, nullptr); } , WITH_SIGNAL(SIGSEGV));
+ ASSERT_DEATH([]() { LIBC_NAMESPACE::strcpy(nullptr, nullptr); },
+ WITH_SIGNAL(SIGSEGV));
}
diff --git a/libc/test/src/string/strsep_test.cpp b/libc/test/src/string/strsep_test.cpp
index 3aacf941a655f2..937e3ea35e0872 100644
--- a/libc/test/src/string/strsep_test.cpp
+++ b/libc/test/src/string/strsep_test.cpp
@@ -53,5 +53,6 @@ TEST(LlvmLibcStrsepTest, DelimitersShouldNotBeIncludedInToken) {
}
}
TEST(LlvmLibcStrsepTest, CrashOnNullPtr) {
- ASSERT_DEATH( [](){LIBC_NAMESPACE::strsep(nullptr, nullptr);} , WITH_SIGNAL(SIGSEGV));
+ ASSERT_DEATH([]() { LIBC_NAMESPACE::strsep(nullptr, nullptr); },
+ WITH_SIGNAL(SIGSEGV));
}
diff --git a/libc/test/src/string/strspn_test.cpp b/libc/test/src/string/strspn_test.cpp
index c53d05e1db4d90..55d237d832cd97 100644
--- a/libc/test/src/string/strspn_test.cpp
+++ b/libc/test/src/string/strspn_test.cpp
@@ -86,5 +86,6 @@ TEST(LlvmLibcStrSpnTest, DuplicatedCharactersToBeSearchedForShouldStillMatch) {
}
TEST(LlvmLibcStrSpnTest, CrashOnNullPtr) {
- ASSERT_DEATH([](){ LIBC_NAMESPACE::strspn(nullptr, nullptr); } , WITH_SIGNAL(SIGSEGV));
+ ASSERT_DEATH([]() { LIBC_NAMESPACE::strspn(nullptr, nullptr); },
+ WITH_SIGNAL(SIGSEGV));
}
\ No newline at end of file
>From 6f48d447821019f95235f52afc3099859763c162 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Mon, 23 Dec 2024 00:14:21 +0200
Subject: [PATCH 29/35] Patch up memcmp test
---
libc/test/src/string/memcmp_test.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libc/test/src/string/memcmp_test.cpp b/libc/test/src/string/memcmp_test.cpp
index 45180c18df0711..ac0ef4192c64ae 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,9 +66,8 @@ TEST(LlvmLibcMemcmpTest, SizeSweep) {
}
}
-#include "hdr/signal_macros.h"
TEST(LlvmLibcMemcmpTest, CrashOnNullPtr) {
- ASSERT_DEATH([]() { LIBC_NAMESPACE::memcmp(nullptr, 1, 1); },
+ ASSERT_DEATH([]() { LIBC_NAMESPACE::memcmp(nullptr, nullptr, 1); },
WITH_SIGNAL(SIGSEGV));
}
>From c3b66d9fe74b53a90f09d738b408a9853f00eda7 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Mon, 23 Dec 2024 00:14:33 +0200
Subject: [PATCH 30/35] Patch up memcpy test
---
libc/test/src/string/memcpy_test.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libc/test/src/string/memcpy_test.cpp b/libc/test/src/string/memcpy_test.cpp
index 430252e39f013c..20e01ec8f6e2ec 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,9 +73,8 @@ TEST(LlvmLibcMemcpyTest, CheckAccess) {
#endif // !defined(LIBC_FULL_BUILD) && defined(LIBC_TARGET_OS_IS_LINUX)
-#include "hdr/signal_macros.h"
TEST(LlvmLibcMemcpyTest, CrashOnNullPtr) {
- ASSERT_DEATH(LIBC_NAMESPACE::memcpy(nullptr, nullptr, 1),
+ ASSERT_DEATH([](){LIBC_NAMESPACE::memcpy(nullptr, nullptr, 1);},
WITH_SIGNAL(SIGSEGV));
}
>From f9ed82cd2b2ba4a18bbed9e1a4c9437bb29f3f66 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Mon, 23 Dec 2024 00:14:54 +0200
Subject: [PATCH 31/35] Only USe unit tests for memcmp test suites
---
libc/cmake/modules/LLVMLibCTestRules.cmake | 3 ++-
libc/test/src/string/CMakeLists.txt | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 10bb9c9487d636..7d38a698a87bf0 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -849,7 +849,7 @@ function(add_libc_test test_name)
endfunction(add_libc_test)
# Tests all implementations that can run on the target CPU.
-function(add_libc_multi_impl_test name suite)
+function(add_libc_multi_impl_test unit_test_only name suite)
get_property(fq_implementations GLOBAL PROPERTY ${name}_implementations)
foreach(fq_config_name IN LISTS fq_implementations)
get_target_property(required_cpu_features ${fq_config_name} REQUIRE_CPU_FEATURES)
@@ -860,6 +860,7 @@ function(add_libc_multi_impl_test name suite)
string(SUBSTRING ${fq_config_name} ${name_loc} -1 target_name)
add_libc_test(
${target_name}_test
+ ${unit_test_only}
SUITE
${suite}
COMPILE_OPTIONS
diff --git a/libc/test/src/string/CMakeLists.txt b/libc/test/src/string/CMakeLists.txt
index 109ef3e4da6a2c..e14c97e1063218 100644
--- a/libc/test/src/string/CMakeLists.txt
+++ b/libc/test/src/string/CMakeLists.txt
@@ -383,7 +383,7 @@ add_libc_test(
libc.src.string.memset_explicit
)
-add_libc_multi_impl_test(memcmp libc-string-tests SRCS memcmp_test.cpp)
+add_libc_multi_impl_test(memcmp UNIT_TEST_ONLY libc-string-tests SRCS memcmp_test.cpp)
add_libc_multi_impl_test(memcpy libc-string-tests SRCS memcpy_test.cpp)
add_libc_multi_impl_test(memmove libc-string-tests SRCS memmove_test.cpp)
add_libc_multi_impl_test(memset libc-string-tests SRCS memset_test.cpp)
>From 96aa07a0b7466571d7361f3c588062b74b52b135 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 27 Dec 2024 03:13:15 +0200
Subject: [PATCH 32/35] Add Unit Tests to remaining suites
---
libc/test/src/string/CMakeLists.txt | 6 +++---
libc/test/src/string/memcmp_test.cpp | 4 ++++
libc/test/src/string/memcpy_test.cpp | 9 ++++++---
libc/test/src/string/memmove_test.cpp | 10 ++++++++++
libc/test/src/string/memset_test.cpp | 10 ++++++++++
5 files changed, 33 insertions(+), 6 deletions(-)
diff --git a/libc/test/src/string/CMakeLists.txt b/libc/test/src/string/CMakeLists.txt
index e14c97e1063218..41b44e6f6913c5 100644
--- a/libc/test/src/string/CMakeLists.txt
+++ b/libc/test/src/string/CMakeLists.txt
@@ -384,6 +384,6 @@ add_libc_test(
)
add_libc_multi_impl_test(memcmp UNIT_TEST_ONLY libc-string-tests SRCS memcmp_test.cpp)
-add_libc_multi_impl_test(memcpy libc-string-tests SRCS memcpy_test.cpp)
-add_libc_multi_impl_test(memmove libc-string-tests SRCS memmove_test.cpp)
-add_libc_multi_impl_test(memset libc-string-tests SRCS memset_test.cpp)
+add_libc_multi_impl_test(memcpy UNIT_TEST_ONLY libc-string-tests SRCS memcpy_test.cpp)
+add_libc_multi_impl_test(memmove UNIT_TEST_ONLY libc-string-tests SRCS memmove_test.cpp)
+add_libc_multi_impl_test(memset UNIT_TEST_ONLY libc-string-tests SRCS memset_test.cpp)
diff --git a/libc/test/src/string/memcmp_test.cpp b/libc/test/src/string/memcmp_test.cpp
index ac0ef4192c64ae..4dd2482c5b2850 100644
--- a/libc/test/src/string/memcmp_test.cpp
+++ b/libc/test/src/string/memcmp_test.cpp
@@ -66,9 +66,13 @@ TEST(LlvmLibcMemcmpTest, SizeSweep) {
}
}
+#if defined(LIBC_TARGET_OS_IS_LINUX)
+
TEST(LlvmLibcMemcmpTest, CrashOnNullPtr) {
ASSERT_DEATH([]() { LIBC_NAMESPACE::memcmp(nullptr, nullptr, 1); },
WITH_SIGNAL(SIGSEGV));
}
+#endif // defined(LIBC_TARGET_OS_IS_LINUX)
+
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/string/memcpy_test.cpp b/libc/test/src/string/memcpy_test.cpp
index 20e01ec8f6e2ec..bca3ef84f902a1 100644
--- a/libc/test/src/string/memcpy_test.cpp
+++ b/libc/test/src/string/memcpy_test.cpp
@@ -73,9 +73,12 @@ TEST(LlvmLibcMemcpyTest, CheckAccess) {
#endif // !defined(LIBC_FULL_BUILD) && defined(LIBC_TARGET_OS_IS_LINUX)
+#if defined(LIBC_TARGET_OS_IS_LINUX)
+
TEST(LlvmLibcMemcpyTest, CrashOnNullPtr) {
- ASSERT_DEATH([](){LIBC_NAMESPACE::memcpy(nullptr, nullptr, 1);},
+ ASSERT_DEATH([]() { LIBC_NAMESPACE::memcpy(nullptr, nullptr, 1); },
WITH_SIGNAL(SIGSEGV));
-}
-} // namespace LIBC_NAMESPACE_DECL
+#endif // defined(LIBC_TARGET_OS_IS_LINUX)
+
+} // namespace LIBC_NAMESPACE_DECL
\ No newline at end of file
diff --git a/libc/test/src/string/memmove_test.cpp b/libc/test/src/string/memmove_test.cpp
index e280b5d25f6f49..75dbb90600ebef 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"
@@ -102,4 +103,13 @@ TEST(LlvmLibcMemmoveTest, SizeSweep) {
}
}
+#if defined(LIBC_TARGET_OS_IS_LINUX)
+
+TEST(LlvmLibcMemmoveTest, CrashOnNullPtr) {
+ ASSERT_DEATH([](){ LIBC_NAMESPACE::memmove(nullptr, nullptr, 0); },
+ WITH_SIGNAL(SIGSEGV));
+}
+
+#endif // LIBC_TARGET_OS_IS_LINUX
+
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/string/memset_test.cpp b/libc/test/src/string/memset_test.cpp
index 774a321ddfce63..a373e68bf7700d 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_TARGET_OS_IS_LINUX)
+
+TEST(LlvmLibcMemsetTest, CrashOnNullPtr) {
+ ASSERT_DEATH([](){ LIBC_NAMESPACE::memset(nullptr, 0, 1); },
+ WITH_SIGNAL(SIGSEGV));
+}
+
+#endif // defined(LIBC_TARGET_OS_IS_LINUX)
+
} // namespace LIBC_NAMESPACE_DECL
>From ef8f357da2cbc0c42240d1c1395571fe942d80a5 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 27 Dec 2024 03:13:39 +0200
Subject: [PATCH 33/35] Formatting
---
libc/test/src/string/memmove_test.cpp | 2 +-
libc/test/src/string/memset_test.cpp | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/libc/test/src/string/memmove_test.cpp b/libc/test/src/string/memmove_test.cpp
index 75dbb90600ebef..df226f7600cb52 100644
--- a/libc/test/src/string/memmove_test.cpp
+++ b/libc/test/src/string/memmove_test.cpp
@@ -106,7 +106,7 @@ TEST(LlvmLibcMemmoveTest, SizeSweep) {
#if defined(LIBC_TARGET_OS_IS_LINUX)
TEST(LlvmLibcMemmoveTest, CrashOnNullPtr) {
- ASSERT_DEATH([](){ LIBC_NAMESPACE::memmove(nullptr, nullptr, 0); },
+ ASSERT_DEATH([]() { LIBC_NAMESPACE::memmove(nullptr, nullptr, 0); },
WITH_SIGNAL(SIGSEGV));
}
diff --git a/libc/test/src/string/memset_test.cpp b/libc/test/src/string/memset_test.cpp
index a373e68bf7700d..f68628c90f11b9 100644
--- a/libc/test/src/string/memset_test.cpp
+++ b/libc/test/src/string/memset_test.cpp
@@ -63,7 +63,7 @@ TEST(LlvmLibcMemsetTest, CheckAccess) {
#if defined(LIBC_TARGET_OS_IS_LINUX)
TEST(LlvmLibcMemsetTest, CrashOnNullPtr) {
- ASSERT_DEATH([](){ LIBC_NAMESPACE::memset(nullptr, 0, 1); },
+ ASSERT_DEATH([]() { LIBC_NAMESPACE::memset(nullptr, 0, 1); },
WITH_SIGNAL(SIGSEGV));
}
>From f42f758748119d27bfc7aa93bc1c097499dbcbbe Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 27 Dec 2024 03:21:22 +0200
Subject: [PATCH 34/35] add if def guards for linux to all AssertDeath tests
---
libc/test/src/string/memchr_test.cpp | 6 +++++-
libc/test/src/string/mempcpy_test.cpp | 6 +++++-
libc/test/src/string/memrchr_test.cpp | 4 ++++
libc/test/src/string/stpncpy_test.cpp | 5 +++++
libc/test/src/string/strcat_test.cpp | 6 +++++-
libc/test/src/string/strcoll_test.cpp | 5 +++++
libc/test/src/string/strcpy_test.cpp | 4 ++++
libc/test/src/string/strsep_test.cpp | 5 +++++
libc/test/src/string/strspn_test.cpp | 6 +++++-
9 files changed, 43 insertions(+), 4 deletions(-)
diff --git a/libc/test/src/string/memchr_test.cpp b/libc/test/src/string/memchr_test.cpp
index 2950672d751846..3a77f6772e2b0f 100644
--- a/libc/test/src/string/memchr_test.cpp
+++ b/libc/test/src/string/memchr_test.cpp
@@ -122,7 +122,11 @@ TEST(LlvmLibcMemChrTest, SignedCharacterFound) {
ASSERT_EQ(actual[0], c);
}
+#if defined(LIBC_TARGET_OS_IS_LINUX)
+
TEST(LlvmLibcMemChrTest, CrashOnNullPtr) {
ASSERT_DEATH([]() { LIBC_NAMESPACE::memchr(nullptr, 1, 1); },
WITH_SIGNAL(SIGSEGV));
-}
\ No newline at end of file
+}
+
+#endif // defined(LIBC_TARGET_OS_IS_LINUX)
\ No newline at end of file
diff --git a/libc/test/src/string/mempcpy_test.cpp b/libc/test/src/string/mempcpy_test.cpp
index af4a05444ec467..601ab90760ba58 100644
--- a/libc/test/src/string/mempcpy_test.cpp
+++ b/libc/test/src/string/mempcpy_test.cpp
@@ -27,7 +27,11 @@ TEST(LlvmLibcMempcpyTest, ZeroCount) {
ASSERT_EQ(static_cast<char *>(result), dest + 0);
}
+#if defined(LIBC_TARGET_OS_IS_LINUX)
+
TEST(LlvmLibcMempcpyTest, CrashOnNullPtr) {
ASSERT_DEATH([]() { LIBC_NAMESPACE::mempcpy(nullptr, nullptr, 0); },
WITH_SIGNAL(SIGSEGV));
-}
\ No newline at end of file
+}
+
+#endif // defined(LIBC_TARGET_OS_IS_LINUX)
\ No newline at end of file
diff --git a/libc/test/src/string/memrchr_test.cpp b/libc/test/src/string/memrchr_test.cpp
index b138801bc27878..90306d46867fd1 100644
--- a/libc/test/src/string/memrchr_test.cpp
+++ b/libc/test/src/string/memrchr_test.cpp
@@ -114,7 +114,11 @@ TEST(LlvmLibcMemRChrTest, ZeroLengthShouldReturnNullptr) {
ASSERT_STREQ(call_memrchr(src, 'd', 0), nullptr);
}
+#if defined(LIBC_TARGET_OS_IS_LINUX)
+
TEST(LlvmLibcMemRChrTest, CrashOnNullPtr) {
ASSERT_DEATH([]() { LIBC_NAMESPACE::memrchr(nullptr, 'd', 1); },
WITH_SIGNAL(SIGSEGV));
}
+
+#endif // defined(LIBC_TARGET_OS_IS_LINUX)
\ No newline at end of file
diff --git a/libc/test/src/string/stpncpy_test.cpp b/libc/test/src/string/stpncpy_test.cpp
index 9f3a8292b5ca67..c8d45d9390babf 100644
--- a/libc/test/src/string/stpncpy_test.cpp
+++ b/libc/test/src/string/stpncpy_test.cpp
@@ -72,7 +72,12 @@ TEST_F(LlvmLibcStpncpyTest, CopyTwoWithNull) {
const char expected[] = {'x', '\0'};
check_stpncpy(dst, src, 2, expected, 1);
}
+
+#if defined(LIBC_TARGET_OS_IS_LINUX)
+
TEST_F(LlvmLibcStpncpyTest, CrashOnNullPtr) {
ASSERT_DEATH([]() { LIBC_NAMESPACE::stpncpy(nullptr, nullptr, 1); },
WITH_SIGNAL(SIGSEGV));
}
+
+#endif // defined(LIBC_TARGET_OS_IS_LINUX)
diff --git a/libc/test/src/string/strcat_test.cpp b/libc/test/src/string/strcat_test.cpp
index 9a0eb7a1645aba..3fc3e95601f94c 100644
--- a/libc/test/src/string/strcat_test.cpp
+++ b/libc/test/src/string/strcat_test.cpp
@@ -37,7 +37,11 @@ TEST(LlvmLibcStrCatTest, NonEmptyDest) {
ASSERT_STREQ(dest, "xyzabc");
}
+#if defined(LIBC_TARGET_OS_IS_LINUX)
+
TEST(LlvmLibcStrCatTest, CrashOnNullPtr) {
ASSERT_DEATH([]() { LIBC_NAMESPACE::strcat(nullptr, nullptr); },
WITH_SIGNAL(SIGSEGV));
-}
\ No newline at end of file
+}
+
+#endif // defined(LIBC_TARGET_OS_IS_LINUX)
\ No newline at end of file
diff --git a/libc/test/src/string/strcoll_test.cpp b/libc/test/src/string/strcoll_test.cpp
index b308bf1653059e..071973d553a772 100644
--- a/libc/test/src/string/strcoll_test.cpp
+++ b/libc/test/src/string/strcoll_test.cpp
@@ -29,7 +29,12 @@ TEST(LlvmLibcStrcollTest, SimpleTest) {
result = LIBC_NAMESPACE::strcoll(s3, s1);
ASSERT_GT(result, 0);
}
+
+#if defined(LIBC_TARGET_OS_IS_LINUX)
+
TEST(LlvmLibcStrcollTest, CrashOnNullPtr) {
ASSERT_DEATH([]() { LIBC_NAMESPACE::strcoll(nullptr, nullptr); },
WITH_SIGNAL(SIGSEGV));
}
+
+#endif // defined(LIBC_TARGET_OS_IS_LINUX)
\ No newline at end of file
diff --git a/libc/test/src/string/strcpy_test.cpp b/libc/test/src/string/strcpy_test.cpp
index f0c328c7342bd2..124898c3430675 100644
--- a/libc/test/src/string/strcpy_test.cpp
+++ b/libc/test/src/string/strcpy_test.cpp
@@ -44,7 +44,11 @@ TEST(LlvmLibcStrCpyTest, OffsetDest) {
ASSERT_STREQ(dest, "xyzabc");
}
+#if defined(LIBC_TARGET_OS_IS_LINUX)
+
TEST(LlvmLibcStrCpyTest, CrashOnNullPtr) {
ASSERT_DEATH([]() { LIBC_NAMESPACE::strcpy(nullptr, nullptr); },
WITH_SIGNAL(SIGSEGV));
}
+
+#endif // defined(LIBC_TARGET_OS_IS_LINUX)
diff --git a/libc/test/src/string/strsep_test.cpp b/libc/test/src/string/strsep_test.cpp
index 937e3ea35e0872..ae8be9f1b3e842 100644
--- a/libc/test/src/string/strsep_test.cpp
+++ b/libc/test/src/string/strsep_test.cpp
@@ -52,7 +52,12 @@ TEST(LlvmLibcStrsepTest, DelimitersShouldNotBeIncludedInToken) {
ASSERT_STREQ(LIBC_NAMESPACE::strsep(&string, "_:"), expected[i]);
}
}
+
+#if defined(LIBC_TARGET_OS_IS_LINUX)
+
TEST(LlvmLibcStrsepTest, CrashOnNullPtr) {
ASSERT_DEATH([]() { LIBC_NAMESPACE::strsep(nullptr, nullptr); },
WITH_SIGNAL(SIGSEGV));
}
+
+#endif // defined(LIBC_TARGET_OS_IS_LINUX)
diff --git a/libc/test/src/string/strspn_test.cpp b/libc/test/src/string/strspn_test.cpp
index 55d237d832cd97..16e0d10a1c07ec 100644
--- a/libc/test/src/string/strspn_test.cpp
+++ b/libc/test/src/string/strspn_test.cpp
@@ -85,7 +85,11 @@ TEST(LlvmLibcStrSpnTest, DuplicatedCharactersToBeSearchedForShouldStillMatch) {
EXPECT_EQ(LIBC_NAMESPACE::strspn("aaaa", "aa"), size_t{4});
}
+#if defined(LIBC_TARGET_OS_IS_LINUX)
+
TEST(LlvmLibcStrSpnTest, CrashOnNullPtr) {
ASSERT_DEATH([]() { LIBC_NAMESPACE::strspn(nullptr, nullptr); },
WITH_SIGNAL(SIGSEGV));
-}
\ No newline at end of file
+}
+
+#endif // defined(LIBC_TARGET_OS_IS_LINUX)
\ No newline at end of file
>From 130bc73f04c0a72edd7b289ae3e65ac0a229afc9 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Tue, 14 Jan 2025 17:27:19 +0200
Subject: [PATCH 35/35] Add Missing extra lines at the eof
---
libc/test/src/string/memchr_test.cpp | 2 +-
libc/test/src/string/memcpy_test.cpp | 2 +-
libc/test/src/string/mempcpy_test.cpp | 2 +-
libc/test/src/string/memrchr_test.cpp | 2 +-
libc/test/src/string/strcat_test.cpp | 2 +-
libc/test/src/string/strcoll_test.cpp | 2 +-
libc/test/src/string/strspn_test.cpp | 2 +-
7 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/libc/test/src/string/memchr_test.cpp b/libc/test/src/string/memchr_test.cpp
index 3a77f6772e2b0f..90cad9f8395960 100644
--- a/libc/test/src/string/memchr_test.cpp
+++ b/libc/test/src/string/memchr_test.cpp
@@ -129,4 +129,4 @@ TEST(LlvmLibcMemChrTest, CrashOnNullPtr) {
WITH_SIGNAL(SIGSEGV));
}
-#endif // defined(LIBC_TARGET_OS_IS_LINUX)
\ No newline at end of file
+#endif // defined(LIBC_TARGET_OS_IS_LINUX)
diff --git a/libc/test/src/string/memcpy_test.cpp b/libc/test/src/string/memcpy_test.cpp
index bca3ef84f902a1..c1788a4b0c4165 100644
--- a/libc/test/src/string/memcpy_test.cpp
+++ b/libc/test/src/string/memcpy_test.cpp
@@ -81,4 +81,4 @@ TEST(LlvmLibcMemcpyTest, CrashOnNullPtr) {
#endif // defined(LIBC_TARGET_OS_IS_LINUX)
-} // namespace LIBC_NAMESPACE_DECL
\ No newline at end of file
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/string/mempcpy_test.cpp b/libc/test/src/string/mempcpy_test.cpp
index 601ab90760ba58..5ec5ee7d5a5407 100644
--- a/libc/test/src/string/mempcpy_test.cpp
+++ b/libc/test/src/string/mempcpy_test.cpp
@@ -34,4 +34,4 @@ TEST(LlvmLibcMempcpyTest, CrashOnNullPtr) {
WITH_SIGNAL(SIGSEGV));
}
-#endif // defined(LIBC_TARGET_OS_IS_LINUX)
\ No newline at end of file
+#endif // defined(LIBC_TARGET_OS_IS_LINUX)
diff --git a/libc/test/src/string/memrchr_test.cpp b/libc/test/src/string/memrchr_test.cpp
index 90306d46867fd1..d4ad1ae04ef3e9 100644
--- a/libc/test/src/string/memrchr_test.cpp
+++ b/libc/test/src/string/memrchr_test.cpp
@@ -121,4 +121,4 @@ TEST(LlvmLibcMemRChrTest, CrashOnNullPtr) {
WITH_SIGNAL(SIGSEGV));
}
-#endif // defined(LIBC_TARGET_OS_IS_LINUX)
\ No newline at end of file
+#endif // defined(LIBC_TARGET_OS_IS_LINUX)
diff --git a/libc/test/src/string/strcat_test.cpp b/libc/test/src/string/strcat_test.cpp
index 3fc3e95601f94c..7d1761846ebcb5 100644
--- a/libc/test/src/string/strcat_test.cpp
+++ b/libc/test/src/string/strcat_test.cpp
@@ -44,4 +44,4 @@ TEST(LlvmLibcStrCatTest, CrashOnNullPtr) {
WITH_SIGNAL(SIGSEGV));
}
-#endif // defined(LIBC_TARGET_OS_IS_LINUX)
\ No newline at end of file
+#endif // defined(LIBC_TARGET_OS_IS_LINUX)
diff --git a/libc/test/src/string/strcoll_test.cpp b/libc/test/src/string/strcoll_test.cpp
index 071973d553a772..dda41987859356 100644
--- a/libc/test/src/string/strcoll_test.cpp
+++ b/libc/test/src/string/strcoll_test.cpp
@@ -37,4 +37,4 @@ TEST(LlvmLibcStrcollTest, CrashOnNullPtr) {
WITH_SIGNAL(SIGSEGV));
}
-#endif // defined(LIBC_TARGET_OS_IS_LINUX)
\ No newline at end of file
+#endif // defined(LIBC_TARGET_OS_IS_LINUX)
diff --git a/libc/test/src/string/strspn_test.cpp b/libc/test/src/string/strspn_test.cpp
index 16e0d10a1c07ec..cfcc4bfafc8724 100644
--- a/libc/test/src/string/strspn_test.cpp
+++ b/libc/test/src/string/strspn_test.cpp
@@ -92,4 +92,4 @@ TEST(LlvmLibcStrSpnTest, CrashOnNullPtr) {
WITH_SIGNAL(SIGSEGV));
}
-#endif // defined(LIBC_TARGET_OS_IS_LINUX)
\ No newline at end of file
+#endif // defined(LIBC_TARGET_OS_IS_LINUX)
More information about the libc-commits
mailing list