Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f393c11

Browse files
committedOct 18, 2019
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
1 parent a11903a commit f393c11

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed
 

‎src/core/qgscoordinatetransform.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,19 +491,18 @@ QgsRectangle QgsCoordinateTransform::transformBoundingBox( const QgsRectangle &r
491491

492492
// 64 points (<=2.12) is not enough, see #13665, for EPSG:4326 -> EPSG:3574 (say that it is a hard one),
493493
// are decent result from about 500 points and more. This method is called quite often, but
494-
// even with 1000 points it takes < 1ms
494+
// even with 1000 points it takes < 1ms.
495495
// TODO: how to effectively and precisely reproject bounding box?
496496
const int nPoints = 1000;
497497
double d = std::sqrt( ( rect.width() * rect.height() ) / std::pow( std::sqrt( static_cast< double >( nPoints ) ) - 1, 2.0 ) );
498-
int nXPoints = static_cast< int >( std::ceil( rect.width() / d ) ) + 1;
499-
int nYPoints = static_cast< int >( std::ceil( rect.height() / d ) ) + 1;
498+
int nXPoints = std::min( static_cast< int >( std::ceil( rect.width() / d ) ) + 1, 1000 );
499+
int nYPoints = std::min( static_cast< int >( std::ceil( rect.height() / d ) ) + 1, 1000 );
500500

501501
QgsRectangle bb_rect;
502502
bb_rect.setMinimal();
503503

504504
// We're interfacing with C-style vectors in the
505505
// end, so let's do C-style vectors here too.
506-
507506
QVector<double> x( nXPoints * nYPoints );
508507
QVector<double> y( nXPoints * nYPoints );
509508
QVector<double> z( nXPoints * nYPoints );

0 commit comments

Comments
 (0)
Please sign in to comment.