Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/checkautovariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 12 additions & 0 deletions test/testautovariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,18 @@ class TestAutoVariables : public TestFixture {
" 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() {
Expand Down