checkautovariables: eliminate false positives on assignment of &ptr->item (#1667)

Even if `ptr` is a local variable, the object `ptr->item` might be not.
So taking address of `ptr->item` is definitely not unsafe in general.

This commit fixes false positives triggered by commit
1.85-249-gf42648fe2 on the following code of sssd:

https://github.com/SSSD/sssd/blob/d409df33/src/sbus/request/sbus_request.c#L359
This commit is contained in:
Kamil Dudka 2019-02-18 09:35:07 +01:00 committed by Daniel Marjamäki
parent 0284705551
commit 2908593cf6
2 changed files with 11 additions and 1 deletions

View File

@ -179,7 +179,7 @@ static bool isAddressOfLocalVariableRecursive(const Token *expr)
const Token *op = expr->astOperand1();
bool deref = false;
while (Token::Match(op, ".|[")) {
if (op->str() == "[")
if (op->str() == "[" || op->originalName() == "->")
deref = true;
op = op->astOperand1();
}

View File

@ -1315,6 +1315,16 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
check("struct s { void *p; };\n"
"extern struct s* f(void);\n"
"void g(void **q)\n"
"{\n"
" struct s *r = f();\n"
" *q = &r->p;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void testconstructor() { // Ticket #5478 - crash while checking a constructor