Fix uninitvar false positive when taking address of variable
This commit is contained in:
parent
80143725dd
commit
e27a7a585f
|
@ -973,6 +973,10 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, Alloc al
|
|||
if (use >= 0)
|
||||
return (use>0);
|
||||
}
|
||||
|
||||
else if (!pointer && Token::simpleMatch(possibleParent, "=") && vartok->astParent()->str() == "&") {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (Token::Match(vartok->previous(), "++|--|%cop%")) {
|
||||
|
|
|
@ -3095,6 +3095,14 @@ private:
|
|||
"}\n", "test.c");
|
||||
ASSERT_EQUALS("[test.c:5]: (error) Uninitialized struct member: ab.b\n", errout.str());
|
||||
|
||||
checkUninitVar("void f(void) {\n"
|
||||
" struct AB ab;\n"
|
||||
" int x;\n"
|
||||
" ab.a = (addr)&x;\n"
|
||||
" dostuff(&ab,0);\n"
|
||||
"}\n", "test.c");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar("class Element {\n"
|
||||
" static void f() { }\n"
|
||||
"};\n"
|
||||
|
|
Loading…
Reference in New Issue