Skip to content

Commit

Permalink
Partial fix for #11894 FP knownArgument with function pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Aug 24, 2023
1 parent 5a7c7b9 commit c25f03e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,8 @@ static void setTokenValue(Token* tok,
});
// Ensure that the comma isn't a function call
if (!callParent || (!Token::Match(callParent->previous(), "%name%|> (") && !Token::simpleMatch(callParent, "{") &&
(!Token::Match(callParent, "( %name%") || settings->library.isNotLibraryFunction(callParent->next())))) {
(!Token::Match(callParent, "( %name%") || settings->library.isNotLibraryFunction(callParent->next())) &&
!(callParent->str() == "(" && Token::simpleMatch(callParent->astOperand1(), "*")))) {
setTokenValue(parent, std::move(value), settings);
return;
}
Expand Down
7 changes: 7 additions & 0 deletions test/testvalueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5129,6 +5129,13 @@ class TestValueFlow : public TestFixture {
value = valueOfTok(code, "1");
ASSERT_EQUALS(1, value.intvalue);
ASSERT_EQUALS(false, value.isKnown());

code = "void f(char c, struct T* t) {\n" // #11894
" (*t->func)(&c, 1, t->ptr);\n"
"}\n";
value = valueOfTok(code, ", 1");
ASSERT_EQUALS(0, value.intvalue);
ASSERT_EQUALS(false, value.isKnown());
}

void valueFlowSizeofForwardDeclaredEnum() {
Expand Down

0 comments on commit c25f03e

Please sign in to comment.