From 2736080f343e8bcdfcdecf8cf8ba30acecb93d4b Mon Sep 17 00:00:00 2001 From: nirvn Date: Fri, 18 Oct 2019 09:59:16 +0700 Subject: [PATCH] Fix assert with negative QVector size in transformBoundingBox This fixes #32302 by insuring that the multilication of nXPoints and nYPoints doesn't result in overflown (and threfore negative) int value --- src/core/qgscoordinatetransform.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/core/qgscoordinatetransform.cpp b/src/core/qgscoordinatetransform.cpp index fef226314f3..88072d23b1d 100644 --- a/src/core/qgscoordinatetransform.cpp +++ b/src/core/qgscoordinatetransform.cpp @@ -517,19 +517,18 @@ QgsRectangle QgsCoordinateTransform::transformBoundingBox( const QgsRectangle &r // 64 points (<=2.12) is not enough, see #13665, for EPSG:4326 -> EPSG:3574 (say that it is a hard one), // are decent result from about 500 points and more. This method is called quite often, but - // even with 1000 points it takes < 1ms + // even with 1000 points it takes < 1ms. // TODO: how to effectively and precisely reproject bounding box? const int nPoints = 1000; double d = std::sqrt( ( rect.width() * rect.height() ) / std::pow( std::sqrt( static_cast< double >( nPoints ) ) - 1, 2.0 ) ); - int nXPoints = static_cast< int >( std::ceil( rect.width() / d ) ) + 1; - int nYPoints = static_cast< int >( std::ceil( rect.height() / d ) ) + 1; + int nXPoints = std::min( static_cast< int >( std::ceil( rect.width() / d ) ) + 1, 1000 ); + int nYPoints = std::min( static_cast< int >( std::ceil( rect.height() / d ) ) + 1, 1000 ); QgsRectangle bb_rect; bb_rect.setMinimal(); // We're interfacing with C-style vectors in the // end, so let's do C-style vectors here too. - QVector x( nXPoints * nYPoints ); QVector y( nXPoints * nYPoints ); QVector z( nXPoints * nYPoints );