Uninitialized variables; Fixed false positive in member assignment
This commit is contained in:
parent
16ce0f1dbf
commit
b115e4a932
|
@ -1020,6 +1020,8 @@ static bool isVoidCast(const Token *tok)
|
||||||
const Token* CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, Alloc alloc, int indirect) const
|
const Token* CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, Alloc alloc, int indirect) const
|
||||||
{
|
{
|
||||||
const Token *valueExpr = vartok; // non-dereferenced , no address of value as variable
|
const Token *valueExpr = vartok; // non-dereferenced , no address of value as variable
|
||||||
|
while (Token::Match(valueExpr->astParent(), ".|::") && astIsRhs(valueExpr))
|
||||||
|
valueExpr = valueExpr->astParent();
|
||||||
if (!pointer) {
|
if (!pointer) {
|
||||||
if (Token::Match(vartok, "%name% [.(]") && vartok->variable() && !vartok->variable()->isPointer() && vartok->variable()->isClass())
|
if (Token::Match(vartok, "%name% [.(]") && vartok->variable() && !vartok->variable()->isPointer() && vartok->variable()->isClass())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -4279,6 +4279,14 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
valueFlowUninit("struct AB { int a; int b; };\n"
|
||||||
|
"void f(void) {\n"
|
||||||
|
" AB ab;\n"
|
||||||
|
" AB *p = &ab;\n"
|
||||||
|
" p->a = 1;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// Unknown types
|
// Unknown types
|
||||||
{
|
{
|
||||||
valueFlowUninit("void a()\n"
|
valueFlowUninit("void a()\n"
|
||||||
|
|
Loading…
Reference in New Issue