Skip to content

Commit 0e1166b

Browse files
authored
fix #13551: Crash in checkStructMemberUsage() (danmar#7217)
1 parent 7fe105c commit 0e1166b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/checkunusedvar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1555,7 +1555,7 @@ void CheckUnusedVar::checkStructMemberUsage()
15551555
tok = tok->next()->astOperand2();
15561556
const ValueType *valueType = tok->valueType();
15571557

1558-
if (!valueType->containerTypeToken)
1558+
if (!valueType || !valueType->containerTypeToken)
15591559
continue;
15601560

15611561
const Type *type = valueType->containerTypeToken->type();

test/testunusedvar.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,6 +2047,15 @@ class TestUnusedVar : public TestFixture {
20472047
" x = y;\n"
20482048
"}\n");
20492049
ASSERT_EQUALS("", errout_str());
2050+
2051+
// #13551 - don't crash
2052+
checkStructMemberUsage("struct S {};\n"
2053+
"void f(vector<std::pair<int, int>> p) {\n"
2054+
" for (auto [a, _] : p) {\n"
2055+
" if (a == 0) {}\n"
2056+
" }\n"
2057+
"}\n");
2058+
ASSERT_EQUALS("", errout_str());
20502059
}
20512060

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

0 commit comments

Comments
 (0)