From c3ae028a411bce1c35b7bed484eaf7f676818aea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 3 Nov 2019 17:08:28 +0100 Subject: [PATCH] Fixed #8617 (False positive: uninitdata for memory allocated and initialized in function called new (C code)) --- lib/checkuninitvar.cpp | 2 +- test/testuninitvar.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 91e7ef56a..774a81b5d 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -720,7 +720,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var 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; // type has constructor(s) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 7cae853c7..b074400f6 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -1719,6 +1719,12 @@ private: "}"); 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..