Fixed #8617 (False positive: uninitdata for memory allocated and initialized in function called new (C code))

This commit is contained in:
Daniel Marjamäki 2019-11-03 17:08:28 +01:00
parent 8c8952ae7c
commit c3ae028a41
2 changed files with 7 additions and 1 deletions

View File

@ -720,7 +720,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
continue; continue;
} }
} }
if (var.isPointer() && (var.typeStartToken()->isStandardType() || var.typeStartToken()->isEnumType() || (var.type() && var.type()->needInitialization == Type::NeedInitialization::True)) && Token::simpleMatch(tok->next(), "= new")) { if (mTokenizer->isCPP() && var.isPointer() && (var.typeStartToken()->isStandardType() || var.typeStartToken()->isEnumType() || (var.type() && var.type()->needInitialization == Type::NeedInitialization::True)) && Token::simpleMatch(tok->next(), "= new")) {
*alloc = CTOR_CALL; *alloc = CTOR_CALL;
// type has constructor(s) // type has constructor(s)

View File

@ -1719,6 +1719,12 @@ private:
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// new in C code does not allocate..
checkUninitVar("int main() {\n"
" char * pBuf = new(10);\n"
" a = *pBuf;\n"
"}", "test.c");
ASSERT_EQUALS("", errout.str());
} }
// class / struct.. // class / struct..