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..