checkuninitvar: Fix FN with c++ casts (#2549)
This commit is contained in:
parent
4f9a0b8420
commit
9896dce7f2
|
@ -713,7 +713,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
|
|||
if (var.isPointer() && Token::simpleMatch(tok->next(), "=")) {
|
||||
const Token *rhs = tok->next()->astOperand2();
|
||||
while (rhs && rhs->isCast())
|
||||
rhs = rhs->astOperand1();
|
||||
rhs = rhs->astOperand2() ? rhs->astOperand2() : rhs->astOperand1();
|
||||
if (rhs && Token::Match(rhs->previous(), "%name% (") &&
|
||||
mSettings->library.returnuninitdata.count(rhs->previous()->str()) > 0U) {
|
||||
*alloc = NO_CTOR_CALL;
|
||||
|
|
|
@ -1478,6 +1478,14 @@ private:
|
|||
"}", "test.cpp", false);
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Memory is allocated but not initialized: buffer\n", errout.str());
|
||||
|
||||
checkUninitVar("void f(){\n"
|
||||
" char *strMsg = \"This is a message\";\n"
|
||||
" char *buffer=static_cast<char*>(malloc(128*sizeof(char)));\n"
|
||||
" strcpy(strMsg,buffer);\n"
|
||||
" free(buffer);\n"
|
||||
"}", "test.cpp", false);
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Memory is allocated but not initialized: buffer\n", errout.str());
|
||||
|
||||
// #3845
|
||||
checkUninitVar("int foo() {\n"
|
||||
" int a[1] = {5};\n"
|
||||
|
|
Loading…
Reference in New Issue