Skip to content

Commit 456fdc4

Browse files
committed
Fix Coverity divide by zero errors
1 parent 943d1a2 commit 456fdc4

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/server/services/wms/qgswmsrenderer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ namespace QgsWms
12191219
{
12201220
mapExtent.invert();
12211221
}
1222-
if ( !mapExtent.isEmpty() )
1222+
if ( !mapExtent.isEmpty() && height > 0 )
12231223
{
12241224
double mapWidthHeightRatio = mapExtent.width() / mapExtent.height();
12251225
double imageWidthHeightRatio = ( double )width / ( double )height;
@@ -1233,7 +1233,7 @@ namespace QgsWms
12331233
}
12341234
}
12351235

1236-
if ( width < 0 || height < 0 )
1236+
if ( width <= 0 || height <= 0 )
12371237
{
12381238
throw QgsException( QStringLiteral( "createImage: Invalid width / height parameters" ) );
12391239
}

tests/src/core/testqgsrasterblock.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ void TestQgsRasterBlock::testWrite()
134134
{
135135
QgsRectangle extent = mpRasterLayer->extent();
136136
int nCols = mpRasterLayer->width(), nRows = mpRasterLayer->height();
137+
QVERIFY( nCols > 0 );
138+
QVERIFY( nRows > 0 );
137139
double tform[] =
138140
{
139141
extent.xMinimum(), extent.width() / nCols, 0.0,

0 commit comments

Comments
 (0)