Uninitialized variables: Fixed false positives when sizeof is used in condition. Ticket: #3369
This commit is contained in:
parent
322f46c761
commit
f09a5b408b
|
@ -1089,6 +1089,8 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
|
|||
uninitvarError(tok2, tok2->str());
|
||||
return true;
|
||||
}
|
||||
if (Token::Match(tok2, "sizeof|decltype|offsetof ("))
|
||||
tok2 = tok2->next()->link();
|
||||
}
|
||||
|
||||
// goto the {
|
||||
|
@ -1141,7 +1143,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
|
|||
}
|
||||
|
||||
// skip sizeof / offsetof
|
||||
if (Token::Match(tok, "sizeof|offsetof ("))
|
||||
if (Token::Match(tok, "sizeof|offsetof|decltype ("))
|
||||
tok = tok->next()->link();
|
||||
|
||||
// TODO: handle loops, try, etc
|
||||
|
|
|
@ -1880,6 +1880,12 @@ private:
|
|||
" sizeof(i+1);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar2("void f() {\n"
|
||||
" int i;\n"
|
||||
" if (100 == sizeof(i+1));\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue