[libc-commits] [PATCH] D68761: Use arrays on stack and avoid use of new and delete operators.
Siva Chandra via Phabricator via libc-commits
libc-commits at lists.llvm.org
Wed Oct 9 22:47:29 PDT 2019
sivachandra created this revision.
sivachandra added a reviewer: nelhage.
Herald added a project: libc-project.
Herald added a subscriber: libc-commits.
Also fix an error found with LLVM_USE_SANITIZER=Address.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D68761
Files:
libc/src/string/strcat/strcat_test.cpp
libc/src/string/strcpy/strcpy_test.cpp
Index: libc/src/string/strcpy/strcpy_test.cpp
===================================================================
--- libc/src/string/strcpy/strcpy_test.cpp
+++ libc/src/string/strcpy/strcpy_test.cpp
@@ -13,19 +13,17 @@
TEST(StrCpyTest, EmptyDest) {
std::string abc = "abc";
- char *dest = new char[4];
+ char dest[4];
char *result = __llvm_libc::strcpy(dest, abc.c_str());
ASSERT_EQ(dest, result);
ASSERT_EQ(std::string(dest), abc);
ASSERT_EQ(std::string(dest).size(), abc.size());
-
- delete[] dest;
}
TEST(StrCpyTest, OffsetDest) {
std::string abc = "abc";
- char *dest = new char[7];
+ char dest[7];
dest[0] = 'x';
dest[1] = 'y';
@@ -35,6 +33,4 @@
ASSERT_EQ(dest + 3, result);
ASSERT_EQ(std::string(dest), std::string("xyz") + abc);
ASSERT_EQ(std::string(dest).size(), abc.size() + 3);
-
- delete[] dest;
}
Index: libc/src/string/strcat/strcat_test.cpp
===================================================================
--- libc/src/string/strcat/strcat_test.cpp
+++ libc/src/string/strcat/strcat_test.cpp
@@ -13,7 +13,7 @@
TEST(StrCatTest, EmptyDest) {
std::string abc = "abc";
- char *dest = new char[4];
+ char dest[4];
dest[0] = '\0';
@@ -21,13 +21,11 @@
ASSERT_EQ(dest, result);
ASSERT_EQ(std::string(dest), abc);
ASSERT_EQ(std::string(dest).size(), abc.size());
-
- delete[] dest;
}
TEST(StrCatTest, NonEmptyDest) {
std::string abc = "abc";
- char *dest = new char[4];
+ char dest[7];
dest[0] = 'x';
dest[1] = 'y';
@@ -38,6 +36,4 @@
ASSERT_EQ(dest, result);
ASSERT_EQ(std::string(dest), std::string("xyz") + abc);
ASSERT_EQ(std::string(dest).size(), abc.size() + 3);
-
- delete[] dest;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68761.224252.patch
Type: text/x-patch
Size: 1703 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20191010/258e4d4e/attachment-0001.bin>
More information about the libc-commits
mailing list