[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
Thu Oct 10 09:08:53 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7a6d98325cd7: Use arrays on stack and avoid use of new and delete operators. (authored by sivachandra).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D68761/new/
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.224384.patch
Type: text/x-patch
Size: 1703 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20191010/d200de46/attachment-0001.bin>
More information about the libc-commits
mailing list