Fixed crash if double constants are passed as default arguments (#6494)
This commit is contained in:
parent
c2b85d1032
commit
f1714110d0
|
@ -1646,6 +1646,8 @@ static void valueFlowFunctionDefaultParameter(TokenList *tokenlist, SymbolDataba
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -62,6 +62,8 @@ private:
|
|||
TEST_CASE(valueFlowForLoop);
|
||||
TEST_CASE(valueFlowSubFunction);
|
||||
TEST_CASE(valueFlowFunctionReturn);
|
||||
|
||||
TEST_CASE(valueFlowFunctionDefaultParameter);
|
||||
}
|
||||
|
||||
bool testValueOfX(const char code[], unsigned int linenr, int value) {
|
||||
|
@ -1422,6 +1424,15 @@ private:
|
|||
"}";
|
||||
ASSERT_EQUALS(15, valueOfTok(code, "*").intvalue);
|
||||
}
|
||||
|
||||
void valueFlowFunctionDefaultParameter() {
|
||||
const char *code;
|
||||
|
||||
code = "class continuous_src_time {\n"
|
||||
" continuous_src_time(std::complex<double> f, double st = 0.0, double et = infinity) {}\n"
|
||||
"};";
|
||||
testValueOfX(code, 2U, 2); // Don't crash (#6494)
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestValueFlow)
|
||||
|
|
Loading…
Reference in New Issue