From f6340c02da948b5ace08fe10f6ebf4bcbf4c798e Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sat, 26 Aug 2023 00:37:10 +0200 Subject: [PATCH] Partial fix for #11894 FP knownArgument with function pointer (#5366) --- lib/valueflow.cpp | 3 ++- test/testvalueflow.cpp | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index f9d3f9425..b97389fe9 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -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; } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 8a075721a..e1302d9ce 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -5129,6 +5129,13 @@ private: 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() {