Fix #10976 false negative: autoVariables [inconclusive] (regression) (#5044)

* Fix #10976 false negative: autoVariables [inconclusive] (regression)

* Use link()

* Use linkAt()

* Skip over [][]
This commit is contained in:
chrchr-github 2023-05-13 14:11:01 +02:00 committed by GitHub
parent dc7550ed9f
commit 6a8c70c1b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -309,8 +309,12 @@ bool CheckAutoVariables::checkAutoVariableAssignment(const Token *expr, bool inc
}
if (Token::simpleMatch(tok, "=")) {
const Token *lhs = tok;
while (Token::Match(lhs->previous(), "%name%|.|*"))
lhs = lhs->previous();
while (Token::Match(lhs->previous(), "%name%|.|*|]")) {
if (lhs->linkAt(-1))
lhs = lhs->linkAt(-1);
else
lhs = lhs->previous();
}
const Token *e = expr;
while (e->str() != "=" && lhs->str() == e->str()) {
e = e->next();

View File

@ -617,6 +617,18 @@ private:
" pcb->root0 = 0;\n" // <- conditional reassign => error
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
check("struct S { int *p; };\n"
"void g(struct S* s) {\n"
" int a[10];\n"
" s->p = a;\n"
" a[0] = 0;\n"
"}\n"
"void f() {\n"
" struct S s;\n"
" g(&s);\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (error, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout.str());
}
void testinvaliddealloc() {