* Assign values to pointers with C++11 init * Handle assigning empty init list * Fix #10596 FN uninitdata with value initialization * Fix test
This commit is contained in:
parent
6a8c70c1b9
commit
096d3a78b0
|
@ -565,7 +565,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
|
||||||
}
|
}
|
||||||
|
|
||||||
// = { .. }
|
// = { .. }
|
||||||
else if (Token::simpleMatch(tok, "= {")) {
|
else if (Token::simpleMatch(tok, "= {") || (Token::Match(tok, "%name% {") && tok->variable() && tok == tok->variable()->nameToken())) {
|
||||||
// end token
|
// end token
|
||||||
const Token *end = tok->next()->link();
|
const Token *end = tok->next()->link();
|
||||||
|
|
||||||
|
@ -657,7 +657,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unknown or unhandled inner scope
|
// Unknown or unhandled inner scope
|
||||||
else if (Token::simpleMatch(tok, ") {") || (Token::Match(tok, "%name% {") && tok->str() != "try")) {
|
else if (Token::simpleMatch(tok, ") {") || (Token::Match(tok, "%name% {") && tok->str() != "try" && !(tok->variable() && tok == tok->variable()->nameToken()))) {
|
||||||
if (tok->str() == "struct" || tok->str() == "union") {
|
if (tok->str() == "struct" || tok->str() == "union") {
|
||||||
tok = tok->linkAt(1);
|
tok = tok->linkAt(1);
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -2048,6 +2048,15 @@ private:
|
||||||
" A* a = new A{};\n"
|
" A* a = new A{};\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar("int f() {\n" // #10596
|
||||||
|
" int* a = new int;\n"
|
||||||
|
" int i{};\n"
|
||||||
|
" i += *a;\n"
|
||||||
|
" delete a;\n"
|
||||||
|
" return i;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:4]: (error) Memory is allocated but not initialized: a\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// class / struct..
|
// class / struct..
|
||||||
|
|
Loading…
Reference in New Issue