Skip to content

Commit c5b50ed

Browse files
authored
CheckUnusedVar: fixed potential crash with incomplete code in doAssignment() (cppcheck-opensource#5887)
Happened with the IDE integration while I was typing code.
1 parent 9c1b643 commit c5b50ed

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
@@ -474,6 +474,8 @@ static const Token* doAssignment(Variables &variables, const Token *tok, bool de
474474
tok = tok->next();
475475

476476
tok = tok->next();
477+
if (!tok)
478+
return tokOld;
477479
if (tok->str() == "*")
478480
tok = tok->next();
479481

test/testgarbage.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ class TestGarbage : public TestFixture {
252252
TEST_CASE(garbageCode221);
253253
TEST_CASE(garbageCode222); // #10763
254254
TEST_CASE(garbageCode223); // #11639
255+
TEST_CASE(garbageCode224);
255256

256257
TEST_CASE(garbageCodeFuzzerClientMode1); // test cases created with the fuzzer client, mode 1
257258

@@ -1719,6 +1720,9 @@ class TestGarbage : public TestFixture {
17191720
void garbageCode223() { // #11639
17201721
ASSERT_THROW(checkCode("struct{}*"), InternalError); // don't crash
17211722
}
1723+
void garbageCode224() {
1724+
checkCode("void f(){ auto* b = dynamic_cast<const }"); // don't crash
1725+
}
17221726

17231727
void syntaxErrorFirstToken() {
17241728
ASSERT_THROW(checkCode("&operator(){[]};"), InternalError); // #7818

0 commit comments

Comments
 (0)