Skip to content

Commit 7fd04cd

Browse files
committed
Updated Token::expressionString(), write '->' instead of '.'
1 parent 28960a8 commit 7fd04cd

File tree

5 files changed

+28
-14
lines changed

5 files changed

+28
-14
lines changed

lib/token.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,13 +1200,17 @@ static const Token* goToRightParenthesis(const Token* start, const Token* end)
12001200

12011201
static std::string stringFromTokenRange(const Token* start, const Token* end)
12021202
{
1203-
std::string ret;
1203+
std::ostringstream ret;
12041204
for (const Token *tok = start; tok && tok != end; tok = tok->next()) {
1205-
ret += tok->str();
1205+
if (tok->originalName() == "->")
1206+
ret << "->";
1207+
else
1208+
ret << tok->str();
12061209
if (Token::Match(tok, "%name%|%num% %name%|%num%"))
1207-
ret += " ";
1210+
ret << ' ';
12081211
}
1209-
return ret + end->str();
1212+
ret << end->str();
1213+
return ret.str();
12101214
}
12111215

12121216
std::string Token::expressionString() const

test/testbufferoverrun.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,8 @@ class TestBufferOverrun : public TestFixture {
460460
" struct ABC* x = malloc(sizeof(struct ABC) + 10);\n"
461461
" x->str[1] = 0;"
462462
"}");
463-
ASSERT_EQUALS("[test.cpp:10]: (error) Array 'x.str[1]' accessed at index 1, which is out of bounds.\n", errout.str());
463+
ASSERT_EQUALS("[test.cpp:10]: (error) Array 'x->str[1]' accessed at index 1, which is out of bounds.\n"
464+
"[test.cpp:10]: (error) Array 'x.str[1]' accessed at index 1, which is out of bounds.\n", errout.str());
464465

465466
// This is not out of bounds because it is a variable length array
466467
// and the index is within the memory allocated.
@@ -582,7 +583,8 @@ class TestBufferOverrun : public TestFixture {
582583
"{\n"
583584
" abc->str[10] = 0;\n"
584585
"}");
585-
ASSERT_EQUALS("[test.cpp:8]: (error) Array 'abc.str[10]' accessed at index 10, which is out of bounds.\n", errout.str());
586+
ASSERT_EQUALS("[test.cpp:8]: (error) Array 'abc->str[10]' accessed at index 10, which is out of bounds.\n"
587+
"[test.cpp:8]: (error) Array 'abc.str[10]' accessed at index 10, which is out of bounds.\n", errout.str());
586588
}
587589

588590
void array_index_9() {
@@ -669,7 +671,8 @@ class TestBufferOverrun : public TestFixture {
669671
" abc->str[10] = 0;\n"
670672
" }\n"
671673
"}");
672-
ASSERT_EQUALS("[test.cpp:13]: (error) Array 'abc.str[10]' accessed at index 10, which is out of bounds.\n", errout.str());
674+
ASSERT_EQUALS("[test.cpp:13]: (error) Array 'abc->str[10]' accessed at index 10, which is out of bounds.\n"
675+
"[test.cpp:13]: (error) Array 'abc.str[10]' accessed at index 10, which is out of bounds.\n", errout.str());
673676
}
674677

675678
void array_index_12() {
@@ -1131,6 +1134,9 @@ class TestBufferOverrun : public TestFixture {
11311134
ASSERT_EQUALS("[test.cpp:9]: (error) Array 'test.a[10]' accessed at index 10, which is out of bounds.\n"
11321135
"[test.cpp:10]: (error) Array 'test.b[10][5]' index test.b[10][2] out of bounds.\n"
11331136
"[test.cpp:11]: (error) Array 'test.b[10][5]' index test.b[0][19] out of bounds.\n"
1137+
"[test.cpp:14]: (error) Array 'ptest->a[10]' accessed at index 10, which is out of bounds.\n"
1138+
"[test.cpp:15]: (error) Array 'ptest->b[10][5]' index ptest->b[10][2] out of bounds.\n"
1139+
"[test.cpp:16]: (error) Array 'ptest->b[10][5]' index ptest->b[0][19] out of bounds.\n"
11341140
"[test.cpp:14]: (error) Array 'ptest.a[10]' accessed at index 10, which is out of bounds.\n"
11351141
"[test.cpp:15]: (error) Array 'ptest.b[10][5]' index ptest.b[10][2] out of bounds.\n"
11361142
"[test.cpp:16]: (error) Array 'ptest.b[10][5]' index ptest.b[0][19] out of bounds.\n", errout.str());
@@ -1151,6 +1157,8 @@ class TestBufferOverrun : public TestFixture {
11511157
"}");
11521158
ASSERT_EQUALS("[test.cpp:8]: (error) Array 'test.a[10][5]' index test.a[9][5] out of bounds.\n"
11531159
"[test.cpp:9]: (error) Array 'test.a[10][5]' index test.a[0][50] out of bounds.\n"
1160+
"[test.cpp:12]: (error) Array 'ptest->a[10][5]' index ptest->a[9][5] out of bounds.\n"
1161+
"[test.cpp:13]: (error) Array 'ptest->a[10][5]' index ptest->a[0][50] out of bounds.\n"
11541162
"[test.cpp:12]: (error) Array 'ptest.a[10][5]' index ptest.a[9][5] out of bounds.\n"
11551163
"[test.cpp:13]: (error) Array 'ptest.a[10][5]' index ptest.a[0][50] out of bounds.\n", errout.str());
11561164
}
@@ -2056,7 +2064,8 @@ class TestBufferOverrun : public TestFixture {
20562064
" struct tt *tt=x;\n"
20572065
" tt->name[22] = 123;\n"
20582066
"}");
2059-
ASSERT_EQUALS("[test.cpp:7]: (error) Array 'tt.name[21]' accessed at index 22, which is out of bounds.\n", errout.str());
2067+
ASSERT_EQUALS("[test.cpp:7]: (error) Array 'tt->name[21]' accessed at index 22, which is out of bounds.\n"
2068+
"[test.cpp:7]: (error) Array 'tt.name[21]' accessed at index 22, which is out of bounds.\n", errout.str());
20602069
}
20612070

20622071
void array_index_valueflow() {
@@ -2908,7 +2917,8 @@ class TestBufferOverrun : public TestFixture {
29082917
" Fred *f; f = new Fred;\n"
29092918
" return f->c[10];\n"
29102919
"}");
2911-
ASSERT_EQUALS("[test.cpp:5]: (error) Array 'f.c[10]' accessed at index 10, which is out of bounds.\n", errout.str());
2920+
ASSERT_EQUALS("[test.cpp:5]: (error) Array 'f->c[10]' accessed at index 10, which is out of bounds.\n"
2921+
"[test.cpp:5]: (error) Array 'f.c[10]' accessed at index 10, which is out of bounds.\n", errout.str());
29122922

29132923
check("static const size_t MAX_SIZE = UNAVAILABLE_TO_CPPCHECK;\n"
29142924
"struct Thing { char data[MAX_SIZE]; };\n"

test/testcondition.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,7 +1583,7 @@ class TestCondition : public TestFixture {
15831583
" if (!tok->next()->function() || \n"
15841584
" (tok->next()->function() && tok->next()->function()->isConstructor()));\n"
15851585
"}");
1586-
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: tok.next().function(). '!A || (A && B)' is equivalent to '!A || B'\n", errout.str());
1586+
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: tok->next()->function(). '!A || (A && B)' is equivalent to '!A || B'\n", errout.str());
15871587

15881588
check("void f() {\n"
15891589
" if (!tok->next()->function() || \n"
@@ -1601,7 +1601,7 @@ class TestCondition : public TestFixture {
16011601
" if (!tok->next(1)->function(1) || \n"
16021602
" (tok->next(1)->function(1) && tok->next(1)->function(1)->isConstructor()));\n"
16031603
"}");
1604-
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: tok.next(1).function(1). '!A || (A && B)' is equivalent to '!A || B'\n", errout.str());
1604+
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: tok->next(1)->function(1). '!A || (A && B)' is equivalent to '!A || B'\n", errout.str());
16051605

16061606
check("void f() {\n"
16071607
" if (!tok->next()->function(1) || \n"

test/testnullpointer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ class TestNullPointer : public TestFixture {
323323
" if (abc && abc->b == 0)\n"
324324
" ;\n"
325325
"}");
326-
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition 'if(abc&&abc.b==0)' is redundant or there is possible null pointer dereference: abc.\n", errout.str());
326+
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition 'if(abc&&abc->b==0)' is redundant or there is possible null pointer dereference: abc.\n", errout.str());
327327

328328
// ok dereferencing in a condition
329329
check("void foo(struct ABC *abc)\n"

test/testother.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2764,7 +2764,7 @@ class TestOther : public TestFixture {
27642764
"void foo(A* a1, A* a2) {\n"
27652765
" a1->b = a1->b;\n"
27662766
"}");
2767-
ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant assignment of 'a1.b' to itself.\n", errout.str());
2767+
ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant assignment of 'a1->b' to itself.\n", errout.str());
27682768

27692769
// #4073 (segmentation fault)
27702770
check("void Foo::myFunc( int a )\n"
@@ -2834,7 +2834,7 @@ class TestOther : public TestFixture {
28342834
"void Foo::func() {\n"
28352835
" this->var = var;\n"
28362836
"}");
2837-
ASSERT_EQUALS("[test.cpp:6]: (warning) Redundant assignment of 'this.var' to itself.\n", errout.str());
2837+
ASSERT_EQUALS("[test.cpp:6]: (warning) Redundant assignment of 'this->var' to itself.\n", errout.str());
28382838

28392839
check("class Foo {\n"
28402840
" int var;\n"

0 commit comments

Comments
 (0)