diff --git a/libc/src/string/CMakeLists.txt b/libc/src/string/CMakeLists.txt --- a/libc/src/string/CMakeLists.txt +++ b/libc/src/string/CMakeLists.txt @@ -246,6 +246,7 @@ .memory_utils.memcpy_implementation .string_utils libc.include.stdlib + libc.src.__support.CPP.new ) add_entrypoint_object( diff --git a/libc/src/string/strndup.cpp b/libc/src/string/strndup.cpp --- a/libc/src/string/strndup.cpp +++ b/libc/src/string/strndup.cpp @@ -10,10 +10,10 @@ #include "src/string/memory_utils/memcpy_implementations.h" #include "src/string/string_utils.h" +#include "src/__support/CPP/new.h" #include "src/__support/common.h" #include -#include namespace __llvm_libc { @@ -23,8 +23,9 @@ size_t len = internal::string_length(src); if (len > size) len = size; - char *dest = reinterpret_cast(::malloc(len + 1)); - if (dest == nullptr) + AllocChecker ac; + char *dest = new (ac) char[len]; + if (!ac) return nullptr; inline_memcpy(dest, src, len + 1); dest[len] = '\0';