Fixed #1189 (false negative: using uninitialized variable i 'a[i] = 0;')
This commit is contained in:
parent
0908728601
commit
4c641ed80c
|
@ -1600,6 +1600,13 @@ private:
|
|||
|
||||
if (tok.varId())
|
||||
{
|
||||
// Used..
|
||||
if (Token::Match(tok.previous(), "[[+-*/] %var% []+-*/]"))
|
||||
{
|
||||
use(foundError, checks, &tok);
|
||||
return &tok;
|
||||
}
|
||||
|
||||
if (Token::Match(tok.previous(), "[;{}] %var% ="))
|
||||
{
|
||||
// using same variable rhs?
|
||||
|
@ -1663,7 +1670,7 @@ private:
|
|||
const Token *tok2 = tok.next()->link();
|
||||
if (Token::simpleMatch(tok2 ? tok2->next() : 0, "="))
|
||||
{
|
||||
ExecutionPath::bailOut(checks);
|
||||
ExecutionPath::bailOutVar(checks, tok.varId());
|
||||
return &tok;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1092,6 +1092,14 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: i\n", errout.str());
|
||||
|
||||
checkUninitVar("static void foo()\n"
|
||||
"{\n"
|
||||
" int ar[10];\n"
|
||||
" int i;\n"
|
||||
" ar[i] = 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: i\n", errout.str());
|
||||
|
||||
checkUninitVar("static void foo()\n"
|
||||
"{\n"
|
||||
" int x, y;\n"
|
||||
|
|
Loading…
Reference in New Issue