Fix 10708: Assertion "!maxValue->isKnown()" from valueFlowInferCondition (#3736)

* Fix 10708: Assertion "!maxValue->isKnown()" from valueFlowInferCondition

* Format
This commit is contained in:
Paul Fultz II 2022-01-21 02:56:24 -06:00 committed by GitHub
parent 57b50e4b00
commit 0737cc4d8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 2 deletions

View File

@ -2126,7 +2126,7 @@ bool Token::addValue(const ValueFlow::Value &value)
}); });
} }
// assert(!value.isPossible() || !mImpl->mValues || std::none_of(mImpl->mValues->begin(), mImpl->mValues->end(), // assert(value.isKnown() || !mImpl->mValues || std::none_of(mImpl->mValues->begin(), mImpl->mValues->end(),
// [&](const ValueFlow::Value& x) { // [&](const ValueFlow::Value& x) {
// return x.isKnown() && sameValueType(x, value); // return x.isKnown() && sameValueType(x, value);
// })); // }));

View File

@ -4450,7 +4450,7 @@ static std::vector<const Token*> getConditions(const Token* tok, const char* op)
return false; return false;
if (tok2->hasKnownIntValue()) if (tok2->hasKnownIntValue())
return false; return false;
if (Token::Match(tok2, "%var%") && !astIsBool(tok2)) if (Token::Match(tok2, "%var%|.") && !astIsBool(tok2))
return false; return false;
return true; return true;
}); });

View File

@ -6197,6 +6197,20 @@ private:
"};\n" "};\n"
"void d::c(int) { e.clear(); }\n"; "void d::c(int) { e.clear(); }\n";
valueOfTok(code, "e"); valueOfTok(code, "e");
code = "struct a {\n"
" int b;\n"
" int c;\n"
"} f;\n"
"unsigned g;\n"
"struct {\n"
" a d;\n"
"} e;\n"
"void h() {\n"
" if (g && f.c)\n"
" e.d.b = g - f.c;\n"
"}\n";
valueOfTok(code, "e");
} }
void valueFlowHang() { void valueFlowHang() {