This commit is contained in:
parent
cf4334904c
commit
ec2f00d7c2
|
@ -1244,7 +1244,7 @@ const Token* CheckUninitVar::isVariableUsage(bool cpp, const Token *vartok, cons
|
||||||
tok = tok->astParent();
|
tok = tok->astParent();
|
||||||
}
|
}
|
||||||
if (Token::simpleMatch(tok->astParent(), "=")) {
|
if (Token::simpleMatch(tok->astParent(), "=")) {
|
||||||
if (astIsLhs(tok))
|
if (astIsLhs(tok) && (alloc == ARRAY || !derefValue || !derefValue->astOperand1() || !derefValue->astOperand1()->isCast()))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (alloc != NO_ALLOC && astIsRhs(valueExpr))
|
if (alloc != NO_ALLOC && astIsRhs(valueExpr))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -2050,6 +2050,14 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
// #1175
|
||||||
|
checkUninitVar("void f() {\n"
|
||||||
|
" int* p = new int;\n"
|
||||||
|
" *((int*)*p) = 42;\n"
|
||||||
|
" delete p;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:3]: (error) Memory is allocated but not initialized: p\n", errout.str());
|
||||||
|
|
||||||
checkUninitVar("int f() {\n" // #10596
|
checkUninitVar("int f() {\n" // #10596
|
||||||
" int* a = new int;\n"
|
" int* a = new int;\n"
|
||||||
" int i{};\n"
|
" int i{};\n"
|
||||||
|
|
Loading…
Reference in New Issue