This commit is contained in:
PKEuS 2012-05-25 07:28:32 -07:00
parent 79445e52ad
commit f4bf94ca4f
2 changed files with 32 additions and 0 deletions

View File

@ -389,6 +389,13 @@ private:
if (tok.varId() && Token::Match(&tok, "%var% [[;]")) { if (tok.varId() && Token::Match(&tok, "%var% [[;]")) {
const Variable* var2 = symbolDatabase->getVariableFromVarId(tok.varId()); const Variable* var2 = symbolDatabase->getVariableFromVarId(tok.varId());
if (var2 && var2->nameToken() == &tok && !var2->isStatic() && !var2->isConst()) { if (var2 && var2->nameToken() == &tok && !var2->isStatic() && !var2->isConst()) {
if (tok.linkAt(1)) { // array
const Token* end = tok.next();
while (end->link())
end = end->link()->next();
if (end->str() != ";")
return &tok;
}
const Scope* parent = var2->scope()->nestedIn; const Scope* parent = var2->scope()->nestedIn;
while (parent) { while (parent) {
for (std::list<Variable>::const_iterator j = parent->varlist.begin(); j != parent->varlist.end(); ++j) { for (std::list<Variable>::const_iterator j = parent->varlist.begin(); j != parent->varlist.end(); ++j) {

View File

@ -1182,6 +1182,31 @@ private:
" free(buffer);\n" " free(buffer);\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: buffer\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: buffer\n", errout.str());
// #3845
checkUninitVar("int foo() {\n"
" int a[1] = {5};\n"
" return a[0];\n"
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar("int foo() {\n"
" int a[2][2] = {{3,4}, {5,6}};\n"
" return a[0][1];\n"
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar("int foo() {\n"
" int a[1];\n"
" return a[0];\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str());
checkUninitVar("int foo() {\n"
" int a[2][2];\n"
" return a[0][1];\n"
"}");
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", "", errout.str());
} }
// alloc.. // alloc..