Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverity scan fixes (3.40 backport) #60328

Merged
merged 4 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/analysis/processing/qgsalgorithmexportmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,12 @@ QVariantMap QgsExportMeshOnGridAlgorithm::processAlgorithm( const QVariantMap &p
}

// grid definition
double gridSpacing = parameterAsDouble( parameters, QStringLiteral( "GRID_SPACING" ), context );
const double gridSpacing = parameterAsDouble( parameters, QStringLiteral( "GRID_SPACING" ), context );
if ( qgsDoubleNear( gridSpacing, 0 ) )
{
throw QgsProcessingException( QObject::tr( "Grid spacing cannot be 0" ) );
}

QgsRectangle extent = parameterAsExtent( parameters, QStringLiteral( "EXTENT" ), context );
if ( extent.isEmpty() )
extent = mTriangularMesh.extent();
Expand Down Expand Up @@ -826,7 +831,12 @@ QVariantMap QgsMeshRasterizeAlgorithm::processAlgorithm( const QVariantMap &para
}

// create raster
double pixelSize = parameterAsDouble( parameters, QStringLiteral( "PIXEL_SIZE" ), context );
const double pixelSize = parameterAsDouble( parameters, QStringLiteral( "PIXEL_SIZE" ), context );
if ( qgsDoubleNear( pixelSize, 0 ) )
{
throw QgsProcessingException( QObject::tr( "Pixel size cannot be 0" ) );
}

QgsRectangle extent = parameterAsExtent( parameters, QStringLiteral( "EXTENT" ), context );
if ( extent.isEmpty() )
extent = mTriangularMesh.extent();
Expand Down
4 changes: 2 additions & 2 deletions src/core/geometry/qgsinternalgeometryengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,9 +841,9 @@ QgsGeometry QgsInternalGeometryEngine::densifyByDistance( double distance ) cons
return QgsGeometry();
}

if ( QgsWkbTypes::geometryType( mGeometry->wkbType() ) == Qgis::GeometryType::Point )
if ( QgsWkbTypes::geometryType( mGeometry->wkbType() ) == Qgis::GeometryType::Point || qgsDoubleNear( distance, 0 ) )
{
return QgsGeometry( mGeometry->clone() ); // point geometry, nothing to do
return QgsGeometry( mGeometry->clone() ); // point geometry (or distance ~= 0), nothing to do
}

if ( const QgsGeometryCollection *gc = qgsgeometry_cast< const QgsGeometryCollection *>( mGeometry ) )
Expand Down
29 changes: 20 additions & 9 deletions src/core/layout/qgslayoutitemmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void QgsLayoutItemMap::setScale( double scaleDenominator, bool forceUpdate )
{
double currentScaleDenominator = scale();

if ( qgsDoubleNear( scaleDenominator, currentScaleDenominator ) || qgsDoubleNear( scaleDenominator, 0.0 ) )
if ( qgsDoubleNear( scaleDenominator, currentScaleDenominator ) || qgsDoubleNear( scaleDenominator, 0.0 ) || qgsDoubleNear( currentScaleDenominator, 0 ) )
{
return;
}
Expand All @@ -205,8 +205,12 @@ void QgsLayoutItemMap::setScale( double scaleDenominator, bool forceUpdate )
QgsScaleCalculator calculator;
calculator.setMapUnits( crs().mapUnits() );
calculator.setDpi( 25.4 ); //QGraphicsView units are mm
scaleRatio = scaleDenominator / calculator.calculate( mExtent, rect().width() );
mExtent.scale( scaleRatio );
const double newScale = calculator.calculate( mExtent, rect().width() );
if ( !qgsDoubleNear( newScale, 0 ) )
{
scaleRatio = scaleDenominator / newScale;
mExtent.scale( scaleRatio );
}
}

invalidateCache();
Expand Down Expand Up @@ -476,8 +480,12 @@ void QgsLayoutItemMap::zoomContent( double factor, QPointF point )
QgsScaleCalculator calculator;
calculator.setMapUnits( crs().mapUnits() );
calculator.setDpi( 25.4 ); //QGraphicsView units are mm
double scaleRatio = scale() / calculator.calculate( mExtent, rect().width() );
mExtent.scale( scaleRatio );
const double newScale = calculator.calculate( mExtent, rect().width() );
if ( !qgsDoubleNear( newScale, 0 ) )
{
const double scaleRatio = scale() / newScale ;
mExtent.scale( scaleRatio );
}
}

//recalculate data defined scale and extents, since that may override zoom
Expand Down Expand Up @@ -1891,8 +1899,8 @@ QgsExpressionContext QgsLayoutItemMap::createExpressionContext() const
const double mapScale = scale();
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_scale" ), mapScale, true ) );

scope->setVariable( QStringLiteral( "zoom_level" ), QgsVectorTileUtils::scaleToZoomLevel( mapScale, 0, 99999 ), true );
scope->setVariable( QStringLiteral( "vector_tile_zoom" ), QgsVectorTileUtils::scaleToZoom( mapScale ), true );
scope->setVariable( QStringLiteral( "zoom_level" ), !qgsDoubleNear( mapScale, 0 ) ? QgsVectorTileUtils::scaleToZoomLevel( mapScale, 0, 99999 ) : 0, true );
scope->setVariable( QStringLiteral( "vector_tile_zoom" ), !qgsDoubleNear( mapScale, 0 ) ? QgsVectorTileUtils::scaleToZoom( mapScale ) : 0, true );

QgsRectangle currentExtent( extent() );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_extent" ), QVariant::fromValue( QgsGeometry::fromRect( currentExtent ) ), true ) );
Expand Down Expand Up @@ -2942,7 +2950,7 @@ void QgsLayoutItemMap::updateAtlasFeature()
double newScale = calc.calculate( newExtent, rect().width() );
newExtent.scale( originalScale / newScale );
}
else if ( mAtlasScalingMode == Predefined )
else if ( mAtlasScalingMode == Predefined && !qgsDoubleNear( originalScale, 0 ) )
{
// choose one of the predefined scales
double newWidth = originalExtent.width();
Expand All @@ -2963,7 +2971,10 @@ void QgsLayoutItemMap::updateAtlasFeature()

//scale newExtent to match desired map scale
//this is required for geographic coordinate systems, where the scale varies by extent
double newScale = calc.calculate( newExtent, rect().width() );
const double newScale = calc.calculate( newExtent, rect().width() );
if ( qgsDoubleNear( newScale, 0 ) )
continue;

newExtent.scale( scales[i] / newScale );

if ( ( newExtent.width() >= bounds.width() ) && ( newExtent.height() >= bounds.height() ) )
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsziputils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ bool QgsZipUtils::decodeGzip( const char *bytesIn, std::size_t size, QByteArray

int ret = inflateInit2( &strm, MAX_WBITS + DEC_MAGIC_NUM_FOR_GZIP );
if ( ret != Z_OK )
{
inflateEnd( &strm );
return false;
}

while ( ret != Z_STREAM_END ) // done when inflate() says it's done
{
Expand Down
Loading