ValueFlow: default argument values are not known, they are possible

This commit is contained in:
Daniel Marjamäki 2015-07-17 16:05:07 +02:00
parent cb04dfbd37
commit 69c1a7ecb1
1 changed files with 12 additions and 5 deletions

View File

@ -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<Token*>(valueTok)->values.front().defaultArg = true;
valueFlowInjectParameter(tokenlist, errorLogger, settings, var, scope, valueTok->values);
const std::list<ValueFlow::Value> &values = var->nameToken()->tokAt(2)->values;
std::list<ValueFlow::Value> argvalues;
for (std::list<ValueFlow::Value>::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);
}
}
}