Fix FP in checkCompareValueOutOfTypeRange when sign is unknown

This commit is contained in:
Daniel Marjamäki 2021-08-29 16:03:45 +02:00
parent 92eb59981d
commit 19fea629c6
2 changed files with 7 additions and 1 deletions

View File

@ -1805,7 +1805,7 @@ void CheckCondition::checkCompareValueOutOfTypeRange()
if (bits == 0 || bits >= 64)
continue;
const auto typeMinValue = (typeTok->valueType()->sign == ValueType::Sign::SIGNED) ? (-(1LL << (bits-1))) : 0;
const auto typeMinValue = (typeTok->valueType()->sign == ValueType::Sign::UNSIGNED) ? 0 : (-(1LL << (bits-1)));
const auto unsignedTypeMaxValue = (1LL << bits) - 1LL;
const auto typeMaxValue = (typeTok->valueType()->sign != ValueType::Sign::SIGNED || bits >= mSettings->int_bit) ?
unsignedTypeMaxValue : // unsigned type. signed int/long/long long; comparing sign bit is ok. i.e. 'i == 0xffffffff'

View File

@ -4573,6 +4573,12 @@ private:
" if (x == ~0LL) {}\n"
"}", &settingsUnix64);
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" char c;\n"
" if ((c = foo()) != -1) {}\n"
"}", &settingsUnix64);
ASSERT_EQUALS("", errout.str());
}
void knownConditionCast() { // #9976