Skip to content

Commit 830249d

Browse files
committed
Fixed danmar#5510 (FP: nullPointer - variable initialized in function call)
1 parent e0574fe commit 830249d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/valueflow.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ static bool bailoutFunctionPar(const Token *tok, const ValueFlow::Value &value,
6161
else
6262
return false;
6363

64+
// reinterpret_cast etc..
65+
if (Token::Match(tok->tokAt(-3), "> ( & %var% ) [,)]") &&
66+
tok->linkAt(-3) &&
67+
Token::Match(tok->linkAt(-3)->tokAt(-2), "[,(] %type% <"))
68+
tok = tok->linkAt(-3);
69+
6470
// goto start of function call and get argnr
6571
unsigned int argnr = 0;
6672
while (tok && tok->str() != "(") {

test/testvalueflow.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,13 @@ class TestValueFlow : public TestFixture {
513513
"}";
514514
ASSERT_EQUALS(false, testValueOfX(code, 4U, 0));
515515

516+
code = "void f() {\n"
517+
" char *x = 0;\n"
518+
" getx(reinterpret_cast<void **>(&x));\n"
519+
" *x = 0;\n"
520+
"}";
521+
ASSERT_EQUALS(false, testValueOfX(code, 4U, 0));
522+
516523
// if/else
517524
code = "void f() {\n"
518525
" int x = 123;\n"

0 commit comments

Comments
 (0)