From 69c1a7ecb1868e29ff7246b2c3f4fecbfdcf818a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 17 Jul 2015 16:05:07 +0200 Subject: [PATCH] ValueFlow: default argument values are not known, they are possible --- lib/valueflow.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 6cefa31a2..ff11c7486 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1938,11 +1938,18 @@ static void valueFlowFunctionDefaultParameter(TokenList *tokenlist, SymbolDataba for (std::size_t arg = function->minArgCount(); arg < function->argCount(); arg++) { const Variable* var = function->getArgumentVar(arg); if (var && var->hasDefault() && Token::Match(var->nameToken(), "%var% = %num%|%str% [,)]")) { - const Token* valueTok = var->nameToken()->tokAt(2); - if (valueTok->values.empty()) - continue; - const_cast(valueTok)->values.front().defaultArg = true; - valueFlowInjectParameter(tokenlist, errorLogger, settings, var, scope, valueTok->values); + const std::list &values = var->nameToken()->tokAt(2)->values; + std::list argvalues; + for (std::list::const_iterator it = values.begin(); it != values.end(); ++it) { + ValueFlow::Value v(*it); + v.defaultArg = true; + if (v.valueKind == ValueFlow::Value::Known) + v.valueKind = ValueFlow::Value::Possible; + if (v.valueKind == ValueFlow::Value::Possible) + argvalues.push_back(v); + } + if (!argvalues.empty()) + valueFlowInjectParameter(tokenlist, errorLogger, settings, var, scope, argvalues); } } }