* Fix #10976 false negative: autoVariables [inconclusive] (regression) * Use link() * Use linkAt() * Skip over [][]
This commit is contained in:
parent
dc7550ed9f
commit
6a8c70c1b9
|
@ -309,8 +309,12 @@ bool CheckAutoVariables::checkAutoVariableAssignment(const Token *expr, bool inc
|
||||||
}
|
}
|
||||||
if (Token::simpleMatch(tok, "=")) {
|
if (Token::simpleMatch(tok, "=")) {
|
||||||
const Token *lhs = tok;
|
const Token *lhs = tok;
|
||||||
while (Token::Match(lhs->previous(), "%name%|.|*"))
|
while (Token::Match(lhs->previous(), "%name%|.|*|]")) {
|
||||||
|
if (lhs->linkAt(-1))
|
||||||
|
lhs = lhs->linkAt(-1);
|
||||||
|
else
|
||||||
lhs = lhs->previous();
|
lhs = lhs->previous();
|
||||||
|
}
|
||||||
const Token *e = expr;
|
const Token *e = expr;
|
||||||
while (e->str() != "=" && lhs->str() == e->str()) {
|
while (e->str() != "=" && lhs->str() == e->str()) {
|
||||||
e = e->next();
|
e = e->next();
|
||||||
|
|
|
@ -617,6 +617,18 @@ private:
|
||||||
" pcb->root0 = 0;\n" // <- conditional reassign => error
|
" 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());
|
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() {
|
void testinvaliddealloc() {
|
||||||
|
|
Loading…
Reference in New Issue