Skip to content

Commit 0e8777e

Browse files
committed
Fixed crash on garbage code (#7356)
1 parent c31f7c7 commit 0e8777e

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

lib/checkunusedvar.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,8 @@ static const Token* doAssignment(Variables &variables, const Token *tok, bool de
490490
tok = tok->next();
491491

492492
tok = tok->tokAt(2);
493+
if (!tok)
494+
return tokOld;
493495
if (tok->str() == "&") {
494496
addressOf = true;
495497
tok = tok->next();

test/testgarbage.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ class TestGarbage : public TestFixture {
222222
TEST_CASE(garbageCode171);
223223
TEST_CASE(garbageCode172);
224224
TEST_CASE(garbageCode173); // #6781
225+
TEST_CASE(garbageCode174); // #7356
225226
TEST_CASE(garbageValueFlow);
226227
TEST_CASE(garbageSymbolDatabase);
227228
TEST_CASE(garbageAST);
@@ -1460,6 +1461,9 @@ class TestGarbage : public TestFixture {
14601461
ASSERT_THROW(checkCode(" template < Types > struct S : >( S < ...Types... > S <) > { ( ) { } } ( ) { return S < void > ( ) }"), InternalError);
14611462
}
14621463

1464+
void garbageCode174() { // #7356
1465+
checkCode("{r e() { w*constD = (())D = cast< }}");
1466+
}
14631467
};
14641468

14651469
REGISTER_TEST(TestGarbage)

0 commit comments

Comments
 (0)