summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSiva Chandra <sivachandra@google.com>2019-10-10 16:06:21 +0000
committerSiva Chandra <sivachandra@google.com>2019-10-10 16:06:21 +0000
commit7a6d98325cd7463868472532391ad13122479380 (patch)
tree7da3d8429c6621ea34d28742209d830320ee72ac
parent94d379095a9c1030582a6ab9199d67d6c64a2642 (diff)
downloadbcm5719-llvm-7a6d98325cd7463868472532391ad13122479380.tar.gz
bcm5719-llvm-7a6d98325cd7463868472532391ad13122479380.zip
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 llvm-svn: 374374
-rw-r--r--libc/src/string/strcat/strcat_test.cpp8
-rw-r--r--libc/src/string/strcpy/strcpy_test.cpp8
2 files changed, 4 insertions, 12 deletions
diff --git a/libc/src/string/strcat/strcat_test.cpp b/libc/src/string/strcat/strcat_test.cpp
index 26bcae2373e..3b8a7a7e447 100644
--- a/libc/src/string/strcat/strcat_test.cpp
+++ b/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 @@ 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;
}
diff --git a/libc/src/string/strcpy/strcpy_test.cpp b/libc/src/string/strcpy/strcpy_test.cpp
index 48f55f24649..e68ea5103db 100644
--- a/libc/src/string/strcpy/strcpy_test.cpp
+++ b/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 @@ 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;
}
OpenPOWER on IntegriCloud