Skip to content

Commit

Permalink
CheckUnusedVar: fixed potential crash with incomplete code in `doAssi…
Browse files Browse the repository at this point in the history
…gnment()` (danmar#5887)

Happened with the IDE integration while I was typing code.
  • Loading branch information
firewave committed Jan 17, 2024
1 parent 9c1b643 commit c5b50ed
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/checkunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@ static const Token* doAssignment(Variables &variables, const Token *tok, bool de
tok = tok->next();

tok = tok->next();
if (!tok)
return tokOld;
if (tok->str() == "*")
tok = tok->next();

Expand Down
4 changes: 4 additions & 0 deletions test/testgarbage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ class TestGarbage : public TestFixture {
TEST_CASE(garbageCode221);
TEST_CASE(garbageCode222); // #10763
TEST_CASE(garbageCode223); // #11639
TEST_CASE(garbageCode224);

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

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

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

0 comments on commit c5b50ed

Please sign in to comment.