QRect: warn about int overflows in debug message
We now print the correct width/height of a rectangle, but we should warn users that the rectangle so built is overflowing the `int` representation. Amends 0f336500a0add3e3a8bb31c5cc605e5e13e23833. Change-Id: Iaed0f3c7457e37e80a9d5efad940d498aa059bd4 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
parent
3a284dc19d
commit
ff0f038ea6
@ -52,6 +52,10 @@ static inline void formatQRect(QDebug &debug, const Rect &rect)
|
|||||||
const qint64 w = qint64(rect.right()) - rect.left() + 1;
|
const qint64 w = qint64(rect.right()) - rect.left() + 1;
|
||||||
const qint64 h = qint64(rect.bottom()) - rect.top() + 1;
|
const qint64 h = qint64(rect.bottom()) - rect.top() + 1;
|
||||||
debug << w << 'x' << h;
|
debug << w << 'x' << h;
|
||||||
|
|
||||||
|
constexpr qint64 M = (std::numeric_limits<int>::max)();
|
||||||
|
if (w > M || h > M)
|
||||||
|
debug << " (oversized)";
|
||||||
} else {
|
} else {
|
||||||
debug << rect.width() << 'x' << rect.height();
|
debug << rect.width() << 'x' << rect.height();
|
||||||
}
|
}
|
||||||
|
@ -4526,7 +4526,7 @@ void tst_QRect::debug()
|
|||||||
|
|
||||||
str.clear();
|
str.clear();
|
||||||
debug << QRect(QPoint(INT_MIN, INT_MIN), QPoint(INT_MAX, INT_MAX));
|
debug << QRect(QPoint(INT_MIN, INT_MIN), QPoint(INT_MAX, INT_MAX));
|
||||||
QCOMPARE(str, "QRect(-2147483648,-2147483648 4294967296x4294967296)");
|
QCOMPARE(str, "QRect(-2147483648,-2147483648 4294967296x4294967296 (oversized))");
|
||||||
}
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QRect)
|
QTEST_MAIN(tst_QRect)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user