Skip to content

Commit a7ded1e

Browse files
committed
Merge branch 'master' of https://github.com/danmar/cppcheck
2 parents 2cfb286 + 7364cc8 commit a7ded1e

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

lib/checkuninitvar.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,9 +1495,12 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
14951495
*alloc = true;
14961496
continue;
14971497
}
1498-
if (var.isPointer() && (_tokenizer->isC() || var.typeStartToken()->isStandardType() || (var.type() && var.type()->needInitialization == Type::True)) && Token::Match(tok->next(), "= new")) {
1499-
if (alloc)
1498+
if (var.isPointer() && (var.typeStartToken()->isStandardType() || (var.type() && var.type()->needInitialization == Type::True)) && Token::Match(tok->next(), "= new")) {
1499+
if (alloc) {
15001500
*alloc = true;
1501+
if (var.typeScope()->numConstructors > 0)
1502+
return false;
1503+
}
15011504
continue;
15021505
}
15031506

test/testuninitvar.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,21 +1455,28 @@ class TestUninitVar : public TestFixture {
14551455
"{\n"
14561456
" Fred *fred = new Fred;\n"
14571457
" fred->foo();\n"
1458-
"};");
1458+
"}");
1459+
ASSERT_EQUALS("", errout.str());
1460+
1461+
checkUninitVarB("struct Fred { int i; Fred(int, float); };\n"
1462+
"void f() {\n"
1463+
" Fred *fred = new Fred(1, 2);\n"
1464+
" fred->foo();\n"
1465+
"}");
14591466
ASSERT_EQUALS("", errout.str());
14601467

14611468
checkUninitVarB("void f()\n"
14621469
"{\n"
14631470
" Fred *fred = malloc(sizeof(Fred));\n"
14641471
" x(&fred->f);\n"
1465-
"};");
1472+
"}");
14661473
ASSERT_EQUALS("", errout.str());
14671474

14681475
checkUninitVarB("void f()\n"
14691476
"{\n"
14701477
" Fred *fred = malloc(sizeof(Fred));\n"
14711478
" x(fred->f);\n"
1472-
"};");
1479+
"}");
14731480
ASSERT_EQUALS("", errout.str());
14741481

14751482
checkUninitVarB("void foo(char *s)\n"

0 commit comments

Comments
 (0)