Fix FP in checkCompareValueOutOfTypeRange when sign is unknown
This commit is contained in:
parent
92eb59981d
commit
19fea629c6
|
@ -1805,7 +1805,7 @@ void CheckCondition::checkCompareValueOutOfTypeRange()
|
||||||
if (bits == 0 || bits >= 64)
|
if (bits == 0 || bits >= 64)
|
||||||
continue;
|
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 unsignedTypeMaxValue = (1LL << bits) - 1LL;
|
||||||
const auto typeMaxValue = (typeTok->valueType()->sign != ValueType::Sign::SIGNED || bits >= mSettings->int_bit) ?
|
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'
|
unsignedTypeMaxValue : // unsigned type. signed int/long/long long; comparing sign bit is ok. i.e. 'i == 0xffffffff'
|
||||||
|
|
|
@ -4573,6 +4573,12 @@ private:
|
||||||
" if (x == ~0LL) {}\n"
|
" if (x == ~0LL) {}\n"
|
||||||
"}", &settingsUnix64);
|
"}", &settingsUnix64);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void f() {\n"
|
||||||
|
" char c;\n"
|
||||||
|
" if ((c = foo()) != -1) {}\n"
|
||||||
|
"}", &settingsUnix64);
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void knownConditionCast() { // #9976
|
void knownConditionCast() { // #9976
|
||||||
|
|
Loading…
Reference in New Issue