Skip to content

Commit 6a8c70c

Browse files
Fix #10976 false negative: autoVariables [inconclusive] (regression) (danmar#5044)
* Fix #10976 false negative: autoVariables [inconclusive] (regression) * Use link() * Use linkAt() * Skip over [][]
1 parent dc7550e commit 6a8c70c

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/checkautovariables.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,12 @@ bool CheckAutoVariables::checkAutoVariableAssignment(const Token *expr, bool inc
309309
}
310310
if (Token::simpleMatch(tok, "=")) {
311311
const Token *lhs = tok;
312-
while (Token::Match(lhs->previous(), "%name%|.|*"))
313-
lhs = lhs->previous();
312+
while (Token::Match(lhs->previous(), "%name%|.|*|]")) {
313+
if (lhs->linkAt(-1))
314+
lhs = lhs->linkAt(-1);
315+
else
316+
lhs = lhs->previous();
317+
}
314318
const Token *e = expr;
315319
while (e->str() != "=" && lhs->str() == e->str()) {
316320
e = e->next();

test/testautovariables.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,18 @@ class TestAutoVariables : public TestFixture {
617617
" pcb->root0 = 0;\n" // <- conditional reassign => error
618618
"}");
619619
ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
620+
621+
check("struct S { int *p; };\n"
622+
"void g(struct S* s) {\n"
623+
" int a[10];\n"
624+
" s->p = a;\n"
625+
" a[0] = 0;\n"
626+
"}\n"
627+
"void f() {\n"
628+
" struct S s;\n"
629+
" g(&s);\n"
630+
"}");
631+
ASSERT_EQUALS("[test.cpp:4]: (error, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout.str());
620632
}
621633

622634
void testinvaliddealloc() {

0 commit comments

Comments
 (0)