Fix issue 9865: false positive: knownConditionTrueFalse (#2764)

This commit is contained in:
Paul Fultz II 2020-09-01 04:22:38 -05:00 committed by GitHub
parent 0a718694af
commit ba84196dca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -4325,6 +4325,8 @@ struct ValueFlowConditionHandler {
if (!values.empty()) {
bool assign = false;
visitAstNodes(parent->astOperand2(), [&](Token* tok2) {
if (tok2 == tok)
return ChildrenToVisit::done;
if (isSameExpression(tokenlist->isCPP(), false, cond.vartok, tok2, settings->library, true, false))
setTokenValue(tok2, values.front(), settings);
else if (Token::Match(tok2, "++|--|=") && isSameExpression(tokenlist->isCPP(),

View File

@ -3412,6 +3412,18 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
// #9865
check("void f(const std::string &s) {\n"
" for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {\n"
" const unsigned char c = static_cast<unsigned char>(*it);\n"
" if (c == '0') {}\n"
" else if ((c == 'a' || c == 'A')\n"
" || (c == 'b' || c == 'B')) {}\n"
" else {}\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void alwaysTrueInfer() {