parent
78c7e3351f
commit
f96e3c9d84
|
@ -1250,8 +1250,15 @@ 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) && (alloc == ARRAY || !derefValue || !derefValue->astOperand1() || !derefValue->astOperand1()->isCast()))
|
if (astIsLhs(tok)) {
|
||||||
|
if (alloc == ARRAY || !derefValue || !derefValue->isUnaryOp("*"))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
const Token* deref = derefValue->astOperand1();
|
||||||
|
while (deref && deref->isCast())
|
||||||
|
deref = deref->astOperand1();
|
||||||
|
if (deref == vartok)
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
if (alloc != NO_ALLOC && astIsRhs(valueExpr))
|
if (alloc != NO_ALLOC && astIsRhs(valueExpr))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2066,6 +2066,20 @@ private:
|
||||||
" return i;\n"
|
" return i;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Memory is allocated but not initialized: a\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Memory is allocated but not initialized: a\n", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar("void* f(size_t n, int i) {\n" // #11766
|
||||||
|
" char* p = (char*)malloc(n);\n"
|
||||||
|
" *(int*)p = i;\n"
|
||||||
|
" return p;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar("void* f(size_t n, int i) {\n"
|
||||||
|
" char* p = (char*)malloc(n);\n"
|
||||||
|
" *(int*)(void*)p = i;\n"
|
||||||
|
" return p;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// class / struct..
|
// class / struct..
|
||||||
|
|
Loading…
Reference in New Issue