Uninitialized variables: Fixed false positive when there is assignment in condition
This commit is contained in:
parent
ddfc968028
commit
d34924ba6d
|
@ -33,6 +33,16 @@ namespace {
|
|||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Skip [ .. ]
|
||||
static const Token * skipBrackets(const Token *tok)
|
||||
{
|
||||
while (tok && tok->str() == "[")
|
||||
tok = tok->link()->next();
|
||||
return tok;
|
||||
}
|
||||
|
||||
|
||||
/// @addtogroup Checks
|
||||
/// @{
|
||||
|
||||
|
@ -860,7 +870,7 @@ private:
|
|||
if (tok.varId() && Token::Match(&tok, "%var% <|<=|==|!=|)"))
|
||||
use(checks, &tok);
|
||||
|
||||
else if (Token::Match(&tok, "!| %var% ["))
|
||||
else if (Token::Match(&tok, "!| %var% [") && !Token::simpleMatch(skipBrackets(tok.next()), "="))
|
||||
use_array_or_pointer_data(checks, tok.str() == "!" ? tok.next() : &tok);
|
||||
|
||||
else if (Token::Match(&tok, "!| %var% (")) {
|
||||
|
|
|
@ -688,6 +688,12 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar("void f() {\n"
|
||||
" char a[10];\n"
|
||||
" if (a[0] = x){}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar("int foo(int x)\n"
|
||||
"{\n"
|
||||
" int i;\n"
|
||||
|
|
Loading…
Reference in New Issue