Fix uninitvar false positive when taking address of variable

This commit is contained in:
Daniel Marjamäki 2019-02-27 18:44:30 +01:00
parent 80143725dd
commit e27a7a585f
2 changed files with 12 additions and 0 deletions

View File

@ -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%")) {

View File

@ -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"