Skip to content

Commit ac7a509

Browse files
Fix #12288 FP: uninitvar (in place new) (danmar#5859)
1 parent bd34a33 commit ac7a509

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/astutils.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -2418,6 +2418,9 @@ bool isVariableChangedByFunctionCall(const Token *tok, int indirect, const Setti
24182418
if (deref && indirect > 0)
24192419
indirect--;
24202420

2421+
if (indirect == 1 && tok->isCpp() && tok->tokAt(-1) && Token::simpleMatch(tok->tokAt(-2), "new (")) // placement new TODO: fix AST
2422+
return true;
2423+
24212424
int argnr;
24222425
tok = getTokenArgumentFunction(tok, argnr);
24232426
if (!tok)

test/testuninitvar.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -6373,6 +6373,12 @@ class TestUninitVar : public TestFixture {
63736373
" g(buf);\n"
63746374
"}\n");
63756375
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: buf\n", errout.str());
6376+
6377+
valueFlowUninit("void f() {\n" // #12288
6378+
" char buf[100];\n"
6379+
" char* p = new (buf) char[100];\n"
6380+
"}\n");
6381+
ASSERT_EQUALS("", errout.str());
63766382
}
63776383

63786384
void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value

0 commit comments

Comments
 (0)