Fix 10433: assertion failure in ValueFlow (Interval::fromValues) (#3419)

This commit is contained in:
Paul Fultz II 2021-08-26 00:46:40 -05:00 committed by GitHub
parent b0407ea6b4
commit 1cd9d0479d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 3 deletions

View File

@ -7050,8 +7050,7 @@ ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Va
funcVar->scope() && funcVar->scope()->function && funcVar->scope()->function->templateDef;
if (type1 == type2)
return ValueType::MatchResult::SAME;
if (!templateVar && type1.find("auto") == std::string::npos && type2.find("auto") == std::string::npos &&
type1 != type2)
if (!templateVar && type1.find("auto") == std::string::npos && type2.find("auto") == std::string::npos)
return ValueType::MatchResult::NOMATCH;
}
return res;

View File

@ -2409,7 +2409,8 @@ bool Token::hasKnownSymbolicValue(const Token* tok) const
return false;
return mImpl->mValues &&
std::any_of(mImpl->mValues->begin(), mImpl->mValues->end(), [&](const ValueFlow::Value& value) {
return value.isSymbolicValue() && value.tokvalue && value.tokvalue->exprId() == tok->exprId();
return value.isKnown() && value.isSymbolicValue() && value.tokvalue &&
value.tokvalue->exprId() == tok->exprId();
});
}

View File

@ -5585,6 +5585,8 @@ struct SymbolicConditionHandler : SimpleConditionHandler {
const Token* valuetok = lhs ? tok->astOperand2() : tok->astOperand1();
if (valuetok->hasKnownSymbolicValue(vartok))
continue;
if (vartok->hasKnownSymbolicValue(valuetok))
continue;
ValueFlow::Value true_value;
ValueFlow::Value false_value;
setConditionalValues(tok, !lhs, 0, true_value, false_value);

View File

@ -5822,6 +5822,16 @@ private:
" a *const d = arguments[c.arg];\n"
"}\n";
valueOfTok(code, "c");
code = "void h(char* p, int s) {\n"
" char *q = p+s;\n"
" char buf[100];\n"
" char *b = buf;\n"
" ++b;\n"
" if (p < q && buf < b)\n"
" diff = (buf-b);\n"
"}\n";
valueOfTok(code, "diff");
}
void valueFlowHang() {