Fix 10430: FP knownConditionTrueFalse with bool from unsigned char (#3416)
This commit is contained in:
parent
8ddc5764f8
commit
f7ddd7a35d
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue