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:
parent
0284705551
commit
2908593cf6
|
@ -179,7 +179,7 @@ static bool isAddressOfLocalVariableRecursive(const Token *expr)
|
||||||
const Token *op = expr->astOperand1();
|
const Token *op = expr->astOperand1();
|
||||||
bool deref = false;
|
bool deref = false;
|
||||||
while (Token::Match(op, ".|[")) {
|
while (Token::Match(op, ".|[")) {
|
||||||
if (op->str() == "[")
|
if (op->str() == "[" || op->originalName() == "->")
|
||||||
deref = true;
|
deref = true;
|
||||||
op = op->astOperand1();
|
op = op->astOperand1();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1315,6 +1315,16 @@ private:
|
||||||
"}");
|
"}");
|
||||||
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
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
|
void testconstructor() { // Ticket #5478 - crash while checking a constructor
|
||||||
|
|
Loading…
Reference in New Issue