Skip to content

Commit 83a816b

Browse files
committed
Fixed crash on garbage code (cppcheck-opensource#7085)
1 parent 6c20f4b commit 83a816b

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

lib/tokenize.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4304,6 +4304,8 @@ void Tokenizer::removeRedundantFor()
43044304
const Token *vartok2 = tok->linkAt(2)->previous();
43054305
if (vartok2->str() == "++")
43064306
vartok2 = vartok2->previous();
4307+
else if (vartok2->strAt(-1) != "++")
4308+
continue;
43074309
if (varname != vartok2->str())
43084310
continue;
43094311

test/testgarbage.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ class TestGarbage : public TestFixture {
197197
TEST_CASE(garbageCode146); // #7081
198198
TEST_CASE(garbageCode147); // #7082
199199
TEST_CASE(garbageCode148); // #7090
200+
TEST_CASE(garbageCode149); // #7085
200201

201202
TEST_CASE(garbageValueFlow);
202203
TEST_CASE(garbageSymbolDatabase);
@@ -1177,6 +1178,13 @@ class TestGarbage : public TestFixture {
11771178
"b[0][0]"), InternalError);
11781179
}
11791180

1181+
void garbageCode149() { // #7085
1182+
checkCode("int main() {\n"
1183+
" for (j = 0; j < 1; j)\n"
1184+
" j6;\n"
1185+
"}");
1186+
}
1187+
11801188
void garbageValueFlow() {
11811189
// #6089
11821190
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"

0 commit comments

Comments
 (0)