Replace a misguided test with a valid one
The code had min and max of an integral type and tested min + min / 2, which naturally overflowed, provoking a compiler warning. The test was meant to be testing min - min / 2; but min is even, so this is just min / 2; and doubling that won't overflow (which is what the test is about). As it happens, min + min / 2 is in fact max - max / 2, which *would* be a good value to test, since max is odd. So add a test for that and remove the broken test. Change-Id: Iec34acbf0d5d7993d41ff844875dc10480b8eb1f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
369305a9be
commit
7d74404325
@ -508,13 +508,13 @@ template <typename Int> static void mulOverflow_template()
|
||||
QCOMPARE(mul_overflow(Int(max / 2), Int(3), &r), true);
|
||||
QCOMPARE(mul_overflow(mid1, Int(mid2 + 1), &r), true);
|
||||
QCOMPARE(mul_overflow(Int(max / 2 + 2), Int(2), &r), true);
|
||||
QCOMPARE(mul_overflow(Int(max - max / 2), Int(2), &r), true);
|
||||
QCOMPARE(mul_overflow(Int(1ULL << (std::numeric_limits<Int>::digits - 1)), Int(2), &r), true);
|
||||
|
||||
if (min) {
|
||||
QCOMPARE(mul_overflow(min, Int(2), &r), true);
|
||||
QCOMPARE(mul_overflow(Int(min / 2), Int(3), &r), true);
|
||||
QCOMPARE(mul_overflow(Int(min / 2 - 1), Int(2), &r), true);
|
||||
QCOMPARE(mul_overflow(Int(min + min/2), Int(2), &r), true);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user