Fixed #904 (false positive: uninitialized variable)
This commit is contained in:
parent
53f7b12b4f
commit
7397bfc765
|
@ -1430,6 +1430,13 @@ void CheckOther::uninitvar()
|
||||||
|
|
||||||
// Is it an array?
|
// Is it an array?
|
||||||
const bool array(tok->next()->str() == "[");
|
const bool array(tok->next()->str() == "[");
|
||||||
|
if (array)
|
||||||
|
{
|
||||||
|
// is the array initialized?
|
||||||
|
if (Token::simpleMatch(tok->next(), "[ ] =") ||
|
||||||
|
Token::Match(tok->next(), "[ %any% ] ="))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// check if variable is accessed uninitialized..
|
// check if variable is accessed uninitialized..
|
||||||
bool init = false;
|
bool init = false;
|
||||||
|
|
|
@ -944,7 +944,6 @@ private:
|
||||||
|
|
||||||
// Check for redundant code..
|
// Check for redundant code..
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings._checkCodingStyle = true;
|
|
||||||
CheckOther checkOther(&tokenizer, &settings, this);
|
CheckOther checkOther(&tokenizer, &settings, this);
|
||||||
checkOther.uninitvar();
|
checkOther.uninitvar();
|
||||||
}
|
}
|
||||||
|
@ -1109,6 +1108,13 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar("void f()\n"
|
||||||
|
"{\n"
|
||||||
|
" char c[50] = \"\";\n"
|
||||||
|
" strcat(c, \"test\");\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkUninitVar("void f()\n"
|
checkUninitVar("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" char s[20];\n"
|
" char s[20];\n"
|
||||||
|
|
Loading…
Reference in New Issue