Skip to content

Commit

Permalink
fix #13551: Crash in checkStructMemberUsage() (#7217)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludviggunne authored Jan 13, 2025
1 parent 7fe105c commit 0e1166b
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 @@ -1555,7 +1555,7 @@ void CheckUnusedVar::checkStructMemberUsage()
tok = tok->next()->astOperand2();
const ValueType *valueType = tok->valueType();

if (!valueType->containerTypeToken)
if (!valueType || !valueType->containerTypeToken)
continue;

const Type *type = valueType->containerTypeToken->type();
Expand Down
9 changes: 9 additions & 0 deletions test/testunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2047,6 +2047,15 @@ class TestUnusedVar : public TestFixture {
" x = y;\n"
"}\n");
ASSERT_EQUALS("", errout_str());

// #13551 - don't crash
checkStructMemberUsage("struct S {};\n"
"void f(vector<std::pair<int, int>> p) {\n"
" for (auto [a, _] : p) {\n"
" if (a == 0) {}\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void functionVariableUsage_(const char* file, int line, const char code[], bool cpp = true) {
Expand Down

0 comments on commit 0e1166b

Please sign in to comment.