Fix 10430: FP knownConditionTrueFalse with bool from unsigned char (#3416)

This commit is contained in:
Paul Fultz II 2021-08-24 21:51:54 -05:00 committed by GitHub
parent 8ddc5764f8
commit f7ddd7a35d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 6 deletions

View File

@ -4716,12 +4716,13 @@ static void valueFlowForwardAssign(Token* const tok,
}
if (tokenlist->isCPP() && vars.size() == 1 && Token::Match(vars.front()->typeStartToken(), "bool|_Bool")) {
std::list<ValueFlow::Value>::iterator it;
for (it = values.begin(); it != values.end(); ++it) {
if (it->isIntValue())
it->intvalue = (it->intvalue != 0);
if (it->isTokValue())
it->intvalue = (it->tokvalue != nullptr);
for (ValueFlow::Value& value : values) {
if (value.isImpossible())
continue;
if (value.isIntValue())
value.intvalue = (value.intvalue != 0);
if (value.isTokValue())
value.intvalue = (value.tokvalue != nullptr);
}
}

View File

@ -2434,6 +2434,16 @@ private:
"}\n";
ASSERT_EQUALS(true, testValueOfX(code, 12U, 0));
ASSERT_EQUALS(false, testValueOfXKnown(code, 12U, 0));
code = "bool f(unsigned char uc) {\n"
" const bool x = uc;\n"
" return x;\n"
"}\n";
ASSERT_EQUALS(true, testValueOfXImpossible(code, 3U, -1));
ASSERT_EQUALS(false, testValueOfXKnown(code, 3U, 1));
ASSERT_EQUALS(false, testValueOfXKnown(code, 3U, 0));
ASSERT_EQUALS(false, testValueOfXImpossible(code, 3U, 0));
ASSERT_EQUALS(false, testValueOfXImpossible(code, 3U, 1));
}
void valueFlowAfterCondition() {