Skip to content

Commit d4765bc

Browse files
committed
Refactorized inefficient usage of std::string and const char[] (part 2).
1 parent dcc245b commit d4765bc

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

test/testmemleak.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,7 +2476,7 @@ class TestMemleakInFunction : public TestFixture {
24762476
" char *p = a(len);\n"
24772477
" delete [] p;\n"
24782478
"}");
2479-
ASSERT_EQUALS(std::string(""), errout.str());
2479+
ASSERT_EQUALS("", errout.str());
24802480

24812481
check("char *a(char *a)\n"
24822482
"{\n"
@@ -2491,7 +2491,7 @@ class TestMemleakInFunction : public TestFixture {
24912491
" else\n"
24922492
" free(p);\n"
24932493
"}");
2494-
ASSERT_EQUALS(std::string(""), errout.str());
2494+
ASSERT_EQUALS("", errout.str());
24952495

24962496
check("char *a()\n"
24972497
"{\n"
@@ -2502,7 +2502,7 @@ class TestMemleakInFunction : public TestFixture {
25022502
" char *p = a();\n"
25032503
" free(p);\n"
25042504
"}");
2505-
ASSERT_EQUALS(std::string(""), errout.str());
2505+
ASSERT_EQUALS("", errout.str());
25062506
check("gchar *a()\n"
25072507
"{\n"
25082508
" return g_malloc(10);\n"
@@ -2512,7 +2512,7 @@ class TestMemleakInFunction : public TestFixture {
25122512
" gchar *p = a();\n"
25132513
" g_free(p);\n"
25142514
"}");
2515-
ASSERT_EQUALS(std::string(""), errout.str());
2515+
ASSERT_EQUALS("", errout.str());
25162516
}
25172517

25182518
void allocfunc3() {
@@ -2623,7 +2623,7 @@ class TestMemleakInFunction : public TestFixture {
26232623
" foo(&tmp);\n"
26242624
" free(tmp);\n"
26252625
"}");
2626-
ASSERT_EQUALS(std::string(""), errout.str());
2626+
ASSERT_EQUALS("", errout.str());
26272627
check("void foo(gchar **str)\n"
26282628
"{\n"
26292629
" g_free(*str);\n"
@@ -2637,7 +2637,7 @@ class TestMemleakInFunction : public TestFixture {
26372637
" foo(&tmp);\n"
26382638
" g_free(tmp);\n"
26392639
"}");
2640-
ASSERT_EQUALS(std::string(""), errout.str());
2640+
ASSERT_EQUALS("", errout.str());
26412641

26422642
//#ticket 1789: getcode other function:
26432643
check("void foo(char **str)\n"
@@ -2655,7 +2655,7 @@ class TestMemleakInFunction : public TestFixture {
26552655
" foo(&tmp);\n"
26562656
" free(tmp);\n"
26572657
"}");
2658-
ASSERT_EQUALS(std::string(""), errout.str());
2658+
ASSERT_EQUALS("", errout.str());
26592659
}
26602660

26612661

@@ -2675,7 +2675,7 @@ class TestMemleakInFunction : public TestFixture {
26752675
"\n"
26762676
" free(expr);\n"
26772677
"}");
2678-
ASSERT_EQUALS(std::string(""), errout.str());
2678+
ASSERT_EQUALS("", errout.str());
26792679
check("static FILE* data()\n"
26802680
"{\n"
26812681
" return fopen(\"data.txt\",\"rt\");\n"
@@ -2691,7 +2691,7 @@ class TestMemleakInFunction : public TestFixture {
26912691
"\n"
26922692
" g_free(expr);\n"
26932693
"}");
2694-
ASSERT_EQUALS(std::string(""), errout.str());
2694+
ASSERT_EQUALS("", errout.str());
26952695
}
26962696

26972697

test/testsimplifytokens.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5241,8 +5241,7 @@ class TestSimplifyTokens : public TestFixture {
52415241

52425242
void simplifyTypedef75() { // ticket #2426
52435243
const char code[] = "typedef _Packed struct S { long l; };\n";
5244-
const std::string expected = "";
5245-
ASSERT_EQUALS(expected, tok(code));
5244+
ASSERT_EQUALS("", tok(code));
52465245
ASSERT_EQUALS("", errout.str());
52475246
}
52485247

test/testtokenize.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7103,8 +7103,7 @@ class TestTokenizer : public TestFixture {
71037103
}
71047104

71057105
void functionpointer4() {
7106-
const char code[] = ""
7107-
"struct S\n"
7106+
const char code[] = "struct S\n"
71087107
"{\n"
71097108
" typedef void (*FP)();\n"
71107109
" virtual FP getFP();\n"

test/testvalueflow.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class TestValueFlow : public TestFixture {
5757
TEST_CASE(valueFlowSubFunction);
5858
}
5959

60-
bool testValueOfX(const std::string &code, unsigned int linenr, int value) {
60+
bool testValueOfX(const char code[], unsigned int linenr, int value) {
6161
Settings settings;
6262

6363
// strcpy cfg
@@ -269,8 +269,8 @@ class TestValueFlow : public TestFixture {
269269
" setx(x);\n"
270270
" if (x == 1) {}\n"
271271
"}";
272-
ASSERT_EQUALS(true, testValueOfX(std::string("void setx(int x);")+code, 2U, 1));
273-
ASSERT_EQUALS(false, testValueOfX(std::string("void setx(int &x);")+code, 2U, 1));
272+
ASSERT_EQUALS(true, testValueOfX((std::string("void setx(int x);")+code).c_str(), 2U, 1));
273+
ASSERT_EQUALS(false, testValueOfX((std::string("void setx(int &x);")+code).c_str(), 2U, 1));
274274
ASSERT_EQUALS(true, testValueOfX(code, 2U, 1));
275275

276276
code = "void f(char* x) {\n"

0 commit comments

Comments
 (0)