Skip to content

Commit 4b1254b

Browse files
committed
Merge pull request danmar#168 from simartin/ticket_4994
Ticket danmar#4994: Don't crash when checking variable scope for invalid input
2 parents 2b3e1a2 + 843833f commit 4b1254b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/symboldatabase.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2256,8 +2256,11 @@ void Scope::getVariableList()
22562256

22572257
// skip return and delete
22582258
else if (Token::Match(tok, "return|delete")) {
2259-
while (tok->next() && tok->next()->str() != ";")
2259+
while (tok->next() &&
2260+
tok->next()->str() != ";" &&
2261+
tok->next()->str() != "}" /* ticket #4994 */) {
22602262
tok = tok->next();
2263+
}
22612264
continue;
22622265
}
22632266

test/testother.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class TestOther : public TestFixture {
7575
TEST_CASE(varScope16);
7676
TEST_CASE(varScope17);
7777
TEST_CASE(varScope18);
78+
TEST_CASE(varScope19); // Ticket #4994
7879

7980
TEST_CASE(oldStylePointerCast);
8081
TEST_CASE(invalidPointerCast);
@@ -1081,6 +1082,15 @@ class TestOther : public TestFixture {
10811082
ASSERT_EQUALS("", errout.str());
10821083
}
10831084

1085+
void varScope19() { // Ticket #4994
1086+
varScope("long f () {\n"
1087+
" return a >> extern\n"
1088+
"}\n"
1089+
"long a = 1 ;\n"
1090+
"long b = 2 ;");
1091+
ASSERT_EQUALS("", errout.str());
1092+
}
1093+
10841094
void checkOldStylePointerCast(const char code[]) {
10851095
// Clear the error buffer..
10861096
errout.str("");

0 commit comments

Comments
 (0)