[libc-commits] [libc] r374374 - Use arrays on stack and avoid use of new and delete operators.
Siva Chandra via libc-commits
libc-commits at lists.llvm.org
Thu Oct 10 09:06:21 PDT 2019
Author: sivachandra
Date: Thu Oct 10 09:06:21 2019
New Revision: 374374
URL: http://llvm.org/viewvc/llvm-project?rev=374374&view=rev
Log:
Use arrays on stack and avoid use of new and delete operators.
Summary: Also fix an error found with LLVM_USE_SANITIZER=Address.
Reviewers: nelhage
Subscribers: libc-commits
Tags: #libc-project
Differential Revision: https://reviews.llvm.org/D68761
Modified:
libc/trunk/src/string/strcat/strcat_test.cpp
libc/trunk/src/string/strcpy/strcpy_test.cpp
Modified: libc/trunk/src/string/strcat/strcat_test.cpp
URL: http://llvm.org/viewvc/llvm-project/libc/trunk/src/string/strcat/strcat_test.cpp?rev=374374&r1=374373&r2=374374&view=diff
==============================================================================
--- libc/trunk/src/string/strcat/strcat_test.cpp (original)
+++ libc/trunk/src/string/strcat/strcat_test.cpp Thu Oct 10 09:06:21 2019
@@ -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 @@ TEST(StrCatTest, EmptyDest) {
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 @@ TEST(StrCatTest, NonEmptyDest) {
ASSERT_EQ(dest, result);
ASSERT_EQ(std::string(dest), std::string("xyz") + abc);
ASSERT_EQ(std::string(dest).size(), abc.size() + 3);
-
- delete[] dest;
}
Modified: libc/trunk/src/string/strcpy/strcpy_test.cpp
URL: http://llvm.org/viewvc/llvm-project/libc/trunk/src/string/strcpy/strcpy_test.cpp?rev=374374&r1=374373&r2=374374&view=diff
==============================================================================
--- libc/trunk/src/string/strcpy/strcpy_test.cpp (original)
+++ libc/trunk/src/string/strcpy/strcpy_test.cpp Thu Oct 10 09:06:21 2019
@@ -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 @@ TEST(StrCpyTest, OffsetDest) {
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;
}
More information about the libc-commits
mailing list