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:
Giuseppe D'Angelo 2025-01-30 16:07:23 +01:00
parent 3a284dc19d
commit ff0f038ea6
2 changed files with 5 additions and 1 deletions

View File

@ -52,6 +52,10 @@ static inline void formatQRect(QDebug &debug, const Rect &rect)
const qint64 w = qint64(rect.right()) - rect.left() + 1;
const qint64 h = qint64(rect.bottom()) - rect.top() + 1;
debug << w << 'x' << h;
constexpr qint64 M = (std::numeric_limits<int>::max)();
if (w > M || h > M)
debug << " (oversized)";
} else {
debug << rect.width() << 'x' << rect.height();
}

View File

@ -4526,7 +4526,7 @@ void tst_QRect::debug()
str.clear();
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)