This commit is contained in:
orbitcowboy 2015-01-22 06:53:23 +01:00
commit a7ded1e19f
2 changed files with 15 additions and 5 deletions

View File

@ -1495,9 +1495,12 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
*alloc = true;
continue;
}
if (var.isPointer() && (_tokenizer->isC() || var.typeStartToken()->isStandardType() || (var.type() && var.type()->needInitialization == Type::True)) && Token::Match(tok->next(), "= new")) {
if (alloc)
if (var.isPointer() && (var.typeStartToken()->isStandardType() || (var.type() && var.type()->needInitialization == Type::True)) && Token::Match(tok->next(), "= new")) {
if (alloc) {
*alloc = true;
if (var.typeScope()->numConstructors > 0)
return false;
}
continue;
}

View File

@ -1455,21 +1455,28 @@ private:
"{\n"
" Fred *fred = new Fred;\n"
" fred->foo();\n"
"};");
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVarB("struct Fred { int i; Fred(int, float); };\n"
"void f() {\n"
" Fred *fred = new Fred(1, 2);\n"
" fred->foo();\n"
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVarB("void f()\n"
"{\n"
" Fred *fred = malloc(sizeof(Fred));\n"
" x(&fred->f);\n"
"};");
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVarB("void f()\n"
"{\n"
" Fred *fred = malloc(sizeof(Fred));\n"
" x(fred->f);\n"
"};");
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVarB("void foo(char *s)\n"