Skip to content
Permalink
Browse files
Fix potential nullptr dereference issue in symbol to SLD conversion
due to incorrect use of static_cast instead of dynamic_cast.

And cleanup logic to make it clearer.
  • Loading branch information
nyalldawson committed Apr 23, 2021
1 parent 5492d14 commit 64707711009c30297eb745d4c38ace33ab9833a3
Showing with 15 additions and 8 deletions.
  1. +8 −4 src/core/symbology/qgsfillsymbollayer.cpp
  2. +7 −4 src/core/symbology/qgslinesymbollayer.cpp
@@ -3662,15 +3662,19 @@ void QgsPointPatternFillSymbolLayer::toSld( QDomDocument &doc, QDomElement &elem
symbolizerElem.appendChild( distanceElem );

QgsSymbolLayer *layer = mMarkerSymbol->symbolLayer( i );
QgsMarkerSymbolLayer *markerLayer = static_cast<QgsMarkerSymbolLayer *>( layer );
if ( !markerLayer )
if ( QgsMarkerSymbolLayer *markerLayer = dynamic_cast<QgsMarkerSymbolLayer *>( layer ) )
{
QString errorMsg = QStringLiteral( "MarkerSymbolLayerV2 expected, %1 found. Skip it." ).arg( layer->layerType() );
markerLayer->writeSldMarker( doc, graphicFillElem, props );
}
else if ( layer )
{
QString errorMsg = QStringLiteral( "QgsMarkerSymbolLayer expected, %1 found. Skip it." ).arg( layer->layerType() );
graphicFillElem.appendChild( doc.createComment( errorMsg ) );
}
else
{
markerLayer->writeSldMarker( doc, graphicFillElem, props );
QString errorMsg = QStringLiteral( "Missing point pattern symbol layer. Skip it." );
graphicFillElem.appendChild( doc.createComment( errorMsg ) );
}
}
}
@@ -2341,14 +2341,17 @@ void QgsMarkerLineSymbolLayer::toSld( QDomDocument &doc, QDomElement &element, c
strokeElem.appendChild( graphicStrokeElem );

QgsSymbolLayer *layer = mMarker->symbolLayer( i );
QgsMarkerSymbolLayer *markerLayer = static_cast<QgsMarkerSymbolLayer *>( layer );
if ( !markerLayer )
if ( QgsMarkerSymbolLayer *markerLayer = dynamic_cast<QgsMarkerSymbolLayer *>( layer ) )
{
graphicStrokeElem.appendChild( doc.createComment( QStringLiteral( "MarkerSymbolLayerV2 expected, %1 found. Skip it." ).arg( layer->layerType() ) ) );
markerLayer->writeSldMarker( doc, graphicStrokeElem, props );
}
else if ( layer )
{
graphicStrokeElem.appendChild( doc.createComment( QStringLiteral( "QgsMarkerSymbolLayer expected, %1 found. Skip it." ).arg( layer->layerType() ) ) );
}
else
{
markerLayer->writeSldMarker( doc, graphicStrokeElem, props );
graphicStrokeElem.appendChild( doc.createComment( QStringLiteral( "Missing marker line symbol layer. Skip it." ) ) );
}

if ( !gap.isEmpty() )

0 comments on commit 6470771

Please sign in to comment.