Skip to content

Commit

Permalink
Fix #12531 Crash in doAssignment() (#6159)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Mar 20, 2024
1 parent e2081e8 commit c98029b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/checkunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const

// assignment
else if ((Token::Match(tok, "%name% [") && Token::simpleMatch(skipBracketsAndMembers(tok->next()), "=")) ||
(tok->isUnaryOp("*") && Token::simpleMatch(tok->astParent(), "=") && Token::simpleMatch(tok->astOperand1(), "+"))) {
(tok->isUnaryOp("*") && astIsLHS(tok) && Token::simpleMatch(tok->astParent(), "=") && Token::simpleMatch(tok->astOperand1(), "+"))) {
const Token *eq = tok;
while (eq && !eq->isAssignmentOp())
eq = eq->astParent();
Expand Down
9 changes: 9 additions & 0 deletions test/testunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ class TestUnusedVar : public TestFixture {

TEST_CASE(crash1);
TEST_CASE(crash2);
TEST_CASE(crash3);
TEST_CASE(usingNamespace); // #4585

TEST_CASE(lambdaFunction); // #5078
Expand Down Expand Up @@ -6916,6 +6917,14 @@ class TestUnusedVar : public TestFixture {
"}"); // #4695
}

void crash3() {
functionVariableUsage("void f(int a, int b, const int* p) {\n" // #12531
" const int* s[] = { p, p + 1, p + 2 };\n"
" a = *(s[a] + b);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'a' is assigned a value that is never used.\n", errout_str());
}

void usingNamespace() {
functionVariableUsage("int foo() {\n"
" using namespace ::com::sun::star::i18n;\n"
Expand Down

0 comments on commit c98029b

Please sign in to comment.