[libc-commits] [PATCH] D140461: [libc][NFC] Use the custom operator new from strndup.
Siva Chandra via Phabricator via libc-commits
libc-commits at lists.llvm.org
Wed Dec 21 12:59:03 PST 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc2f17bfbff80: [libc][NFC] Use the custom operator new from strndup. (authored by sivachandra).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D140461/new/
https://reviews.llvm.org/D140461
Files:
libc/src/string/CMakeLists.txt
libc/src/string/strndup.cpp
Index: libc/src/string/strndup.cpp
===================================================================
--- libc/src/string/strndup.cpp
+++ 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 <stddef.h>
-#include <stdlib.h>
namespace __llvm_libc {
@@ -23,8 +23,9 @@
size_t len = internal::string_length(src);
if (len > size)
len = size;
- char *dest = reinterpret_cast<char *>(::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';
Index: libc/src/string/CMakeLists.txt
===================================================================
--- libc/src/string/CMakeLists.txt
+++ 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(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140461.484651.patch
Type: text/x-patch
Size: 1107 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20221221/997dc56c/attachment-0001.bin>
More information about the libc-commits
mailing list