mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 768538 - 2/2 - Fix undefined behavior in the CheckedInt unit test - r=jwalden
This commit is contained in:
parent
457f2bf3b9
commit
184c216c48
@ -99,17 +99,19 @@ void test()
|
|||||||
const CheckedInt<T> max(detail::MaxValue<T>::value);
|
const CheckedInt<T> max(detail::MaxValue<T>::value);
|
||||||
const CheckedInt<T> min(detail::MinValue<T>::value);
|
const CheckedInt<T> min(detail::MinValue<T>::value);
|
||||||
|
|
||||||
// Check min() and max(), since they are custom implementations and a mistake there
|
// Check MinValue and MaxValue, since they are custom implementations and a mistake there
|
||||||
// could potentially NOT be caught by any other tests... while making everything wrong!
|
// could potentially NOT be caught by any other tests... while making everything wrong!
|
||||||
|
|
||||||
T bit = 1;
|
unsignedT bit = 1;
|
||||||
|
unsignedT unsignedMinValue(min.value());
|
||||||
|
unsignedT unsignedMaxValue(max.value());
|
||||||
for (size_t i = 0; i < sizeof(T) * CHAR_BIT - 1; i++)
|
for (size_t i = 0; i < sizeof(T) * CHAR_BIT - 1; i++)
|
||||||
{
|
{
|
||||||
VERIFY((min.value() & bit) == 0);
|
VERIFY((unsignedMinValue & bit) == 0);
|
||||||
bit <<= 1;
|
bit <<= 1;
|
||||||
}
|
}
|
||||||
VERIFY((min.value() & bit) == (isTSigned ? bit : T(0)));
|
VERIFY((unsignedMinValue & bit) == (isTSigned ? bit : unsignedT(0)));
|
||||||
VERIFY(max.value() == T(~(min.value())));
|
VERIFY(unsignedMaxValue == unsignedT(~unsignedMinValue));
|
||||||
|
|
||||||
const CheckedInt<T> zero(0);
|
const CheckedInt<T> zero(0);
|
||||||
const CheckedInt<T> one(1);
|
const CheckedInt<T> one(1);
|
||||||
@ -117,7 +119,7 @@ void test()
|
|||||||
const CheckedInt<T> three(3);
|
const CheckedInt<T> three(3);
|
||||||
const CheckedInt<T> four(4);
|
const CheckedInt<T> four(4);
|
||||||
|
|
||||||
/* Addition / substraction checks */
|
/* Addition / subtraction checks */
|
||||||
|
|
||||||
VERIFY_IS_VALID(zero + zero);
|
VERIFY_IS_VALID(zero + zero);
|
||||||
VERIFY(zero + zero == zero);
|
VERIFY(zero + zero == zero);
|
||||||
|
Loading…
Reference in New Issue
Block a user