diff --git a/src/corelib/tools/qrect.h b/src/corelib/tools/qrect.h index 59cecf9a01..a0449ae134 100644 --- a/src/corelib/tools/qrect.h +++ b/src/corelib/tools/qrect.h @@ -245,7 +245,7 @@ Q_DECL_CONSTEXPR inline QPoint QRect::bottomLeft() const Q_DECL_NOTHROW { return QPoint(x1, y2); } Q_DECL_CONSTEXPR inline QPoint QRect::center() const Q_DECL_NOTHROW -{ return QPoint((x1+x2)/2, (y1+y2)/2); } +{ return QPoint(int((qint64(x1)+x2)/2), int((qint64(y1)+y2)/2)); } // cast avoids overflow on addition Q_DECL_CONSTEXPR inline int QRect::width() const Q_DECL_NOTHROW { return x2 - x1 + 1; } diff --git a/tests/auto/corelib/tools/qrect/tst_qrect.cpp b/tests/auto/corelib/tools/qrect/tst_qrect.cpp index c6907dcac2..1377e801a7 100644 --- a/tests/auto/corelib/tools/qrect/tst_qrect.cpp +++ b/tests/auto/corelib/tools/qrect/tst_qrect.cpp @@ -2349,7 +2349,7 @@ void tst_QRect::center_data() QTest::newRow( "SmallestQRect" ) << getQRectCase( SmallestQRect ) << QPoint(1,1); QTest::newRow( "MiddleQRect" ) << getQRectCase( MiddleQRect ) << QPoint(0,0); QTest::newRow( "LargestQRect" ) << getQRectCase( LargestQRect ) << QPoint(INT_MAX/2,INT_MAX/2); - QTest::newRow( "SmallestCoordQRect" ) << getQRectCase( SmallestCoordQRect ) << QPoint(0,0); + QTest::newRow( "SmallestCoordQRect" ) << getQRectCase( SmallestCoordQRect ) << QPoint(INT_MIN, INT_MIN); QTest::newRow( "LargestCoordQRect" ) << getQRectCase( LargestCoordQRect ) << QPoint(0,0); QTest::newRow( "RandomQRect" ) << getQRectCase( RandomQRect ) << QPoint(105,207); QTest::newRow( "NegativeSizeQRect" ) << getQRectCase( NegativeSizeQRect ) << QPoint(-4,-4);