Uninitialized variables: Fixed false positives (caused by my 'check more variables' commit)

This commit is contained in:
Daniel Marjamäki 2011-12-26 22:14:52 +01:00
parent 5aaec7adc5
commit 5bac8eca37
2 changed files with 13 additions and 4 deletions

View File

@ -1059,12 +1059,15 @@ void CheckUninitVar::check()
stdtype = true;
else if (tok->str() == "*")
pointer = true;
else if (tok->isName() && tok->next()->str() == ";") {
if (stdtype || pointer || _tokenizer->isC())
else if (Token::Match(tok, "struct %type%"))
tok = tok->next();
else {
if (tok->isName() && tok->next()->str() == ";" &&
(stdtype || pointer)) {
checkScopeForVariable(tok->next(), tok->varId(), pointer, NULL);
}
break;
} else if (!tok->isName())
break;
}
tok = tok->next();
}
}

View File

@ -1739,6 +1739,12 @@ private:
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: abc\n", errout.str());
checkUninitVar2("int f() {\n"
" static int x;\n"
" return ++x;\n"
"}");
ASSERT_EQUALS("", errout.str());
// using uninit var in condition
checkUninitVar2("void f() {\n"
" int x;\n"