From ec4668353d53989bef0567753bde124613b2e324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 26 Dec 2019 18:32:59 +0100 Subject: [PATCH] Verification; Determine argument number properly --- lib/exprengine.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/exprengine.cpp b/lib/exprengine.cpp index 4d4108916..f18010ec6 100644 --- a/lib/exprengine.cpp +++ b/lib/exprengine.cpp @@ -1653,16 +1653,24 @@ void ExprEngine::runChecks(ErrorLogger *errorLogger, const Tokenizer *tokenizer, std::function checkFunctionCall = [=](const Token *tok, const ExprEngine::Value &value, ExprEngine::DataBase *dataBase) { if (!Token::Match(tok->astParent(), "[(,]")) return; - int num = (tok == tok->astParent()->astOperand2()) ? 1 : 0; const Token *parent = tok->astParent(); - while (Token::simpleMatch(parent, ",")) { + while (Token::simpleMatch(parent, ",")) parent = parent->astParent(); - ++num; - } - if (!parent || parent->str() != "(" || num == 0) + if (!parent || parent->str() != "(") return; - if (parent->astOperand1() && parent->astOperand1()->function()) { + int num = 0; + for (const Token *argTok: getArguments(parent->astOperand1())) { + --num; + if (argTok == tok) { + num = -num; + break; + } + } + if (num <= 0) + return; + + if (parent->astOperand1()->function()) { const Variable *arg = parent->astOperand1()->function()->getArgumentVar(num - 1); if (arg->nameToken()) { std::string bad; @@ -1690,6 +1698,7 @@ void ExprEngine::runChecks(ErrorLogger *errorLogger, const Tokenizer *tokenizer, "verificationInvalidArgValue", "There is function call, cannot determine that " + std::to_string(num) + getOrdinalText(num) + " argument value meets the attribute " + bad, CWE(0), false); errorLogger->reportErr(errmsg); + return; } } }