Partial fix for #11894 FP knownArgument with function pointer (#5366)

This commit is contained in:
chrchr-github 2023-08-26 00:37:10 +02:00 committed by GitHub
parent 078e967ab2
commit f6340c02da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -635,7 +635,8 @@ static void setTokenValue(Token* tok,
}); });
// Ensure that the comma isn't a function call // Ensure that the comma isn't a function call
if (!callParent || (!Token::Match(callParent->previous(), "%name%|> (") && !Token::simpleMatch(callParent, "{") && 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); setTokenValue(parent, std::move(value), settings);
return; return;
} }

View File

@ -5129,6 +5129,13 @@ private:
value = valueOfTok(code, "1"); value = valueOfTok(code, "1");
ASSERT_EQUALS(1, value.intvalue); ASSERT_EQUALS(1, value.intvalue);
ASSERT_EQUALS(false, value.isKnown()); 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() { void valueFlowSizeofForwardDeclaredEnum() {