Skip to content

Commit a7f7740

Browse files
committed
More coverity fixes
1 parent dc156c8 commit a7f7740

31 files changed

+114
-44
lines changed

src/app/qgsattributetabledialog.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,11 @@ void QgsAttributeTableDialog::columnBoxInit()
287287

288288
foreach ( const QgsField field, fields )
289289
{
290-
if ( mLayer->editorWidgetV2( mLayer->fieldNameIndex( field.name() ) ) != "Hidden" )
290+
int idx = mLayer->fieldNameIndex( field.name() );
291+
if ( idx < 0 )
292+
continue;
293+
294+
if ( mLayer->editorWidgetV2( idx ) != "Hidden" )
291295
{
292296
QIcon icon = QgsApplication::getThemeIcon( "/mActionNewAttribute.png" );
293297
QString text = field.name();
@@ -650,6 +654,9 @@ void QgsAttributeTableDialog::filterQueryChanged( const QString& query )
650654

651655
const QgsFields& flds = mLayer->pendingFields();
652656
int fldIndex = mLayer->fieldNameIndex( fieldName );
657+
if ( fldIndex < 0 )
658+
return;
659+
653660
QVariant::Type fldType = flds[fldIndex].type();
654661
bool numeric = ( fldType == QVariant::Int || fldType == QVariant::Double );
655662

src/app/qgsfieldsproperties.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,9 @@ void QgsFieldsProperties::on_mDeleteAttributeButton_clicked()
550550
if ( item->column() == 0 )
551551
{
552552
int idx = mIndexedWidgets.indexOf( item );
553+
if ( idx < 0 )
554+
continue;
555+
553556
if ( mLayer->pendingFields().fieldOrigin( idx ) == QgsFields::OriginExpression )
554557
expressionFields << idx;
555558
else

src/app/qgsmaptoolmovelabel.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
QgsMapToolMoveLabel::QgsMapToolMoveLabel( QgsMapCanvas* canvas )
2626
: QgsMapToolLabel( canvas )
27+
, mClickOffsetX( 0 )
28+
, mClickOffsetY( 0 )
2729
{
2830
mToolName = tr( "Move label" );
2931
}

src/app/qgsmergeattributesdialog.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ void QgsMergeAttributesDialog::comboValueChanged( const QString &text )
194194
return;
195195
}
196196
int column = findComboColumn( senderComboBox );
197+
if ( column < 0 )
198+
return;
199+
197200
refreshMergedValue( column );
198201
}
199202

src/core/layertree/qgslayertreemodellegendnode.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ QSizeF QgsRasterSymbolLegendNode::drawSymbol( const QgsLegendSettings& settings,
476476
if ( QgsRasterLayer* rasterLayer = dynamic_cast<QgsRasterLayer*>( layerNode()->layer() ) )
477477
{
478478
if ( QgsRasterRenderer* rasterRenderer = rasterLayer->renderer() )
479-
itemColor.setAlpha( rasterRenderer ? rasterRenderer->opacity() * 255.0 : 255 );
479+
itemColor.setAlpha( rasterRenderer->opacity() * 255.0 );
480480
}
481481

482482
ctx->painter->setBrush( itemColor );

src/core/qgscoordinatetransform.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ extern "C"
3939

4040
QgsCoordinateTransform::QgsCoordinateTransform()
4141
: QObject()
42+
, mShortCircuit( false )
4243
, mInitialisedFlag( false )
4344
, mSourceProjection( 0 )
4445
, mDestinationProjection( 0 )
@@ -50,6 +51,7 @@ QgsCoordinateTransform::QgsCoordinateTransform()
5051

5152
QgsCoordinateTransform::QgsCoordinateTransform( const QgsCoordinateReferenceSystem& source, const QgsCoordinateReferenceSystem& dest )
5253
: QObject()
54+
, mShortCircuit( false )
5355
, mInitialisedFlag( false )
5456
, mSourceProjection( 0 )
5557
, mDestinationProjection( 0 )

src/core/qgscoordinatetransform.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,12 @@ class CORE_EXPORT QgsCoordinateTransform : public QObject
200200
* Flag to indicate whether the coordinate systems have been initialised
201201
* @return true if initialised, otherwise false
202202
*/
203-
bool isInitialised() const {return mInitialisedFlag;};
203+
bool isInitialised() const {return mInitialisedFlag;}
204204

205205
/*! See if the transform short circuits because src and dest are equivalent
206206
* @return bool True if it short circuits
207207
*/
208-
bool isShortCircuited() {return mShortCircuit;};
208+
bool isShortCircuited() {return mShortCircuit;}
209209

210210
/*! Change the destination coordinate system by passing it a qgis srsid
211211
* A QGIS srsid is a unique key value to an entry on the tbl_srs in the

src/core/qgsfeaturerequest.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const QString QgsFeatureRequest::AllAttributes = QString( "#!allattributes!#" );
2424

2525
QgsFeatureRequest::QgsFeatureRequest()
2626
: mFilter( FilterNone )
27+
, mFilterFid( -1 )
2728
, mFilterExpression( 0 )
2829
, mFlags( 0 )
2930
{

src/core/qgsfield.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ bool QgsFields::appendExpressionField( const QgsField& field, int originIndex )
185185

186186
void QgsFields::remove( int fieldIdx )
187187
{
188+
if ( !exists( fieldIdx ) )
189+
return;
190+
188191
mNameToIndex.remove( mFields[fieldIdx].field.name() );
189192
mFields.remove( fieldIdx );
190193
}
@@ -197,6 +200,14 @@ void QgsFields::extend( const QgsFields& other )
197200
}
198201
}
199202

203+
QgsFields::FieldOrigin QgsFields::fieldOrigin( int fieldIdx ) const
204+
{
205+
if ( !exists( fieldIdx ) )
206+
return OriginUnknown;
207+
208+
return mFields[fieldIdx].origin;
209+
}
210+
200211
QList<QgsField> QgsFields::toList() const
201212
{
202213
QList<QgsField> lst;

src/core/qgsfield.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ class CORE_EXPORT QgsFields
231231
const QgsField& field( const QString& name ) const { return mFields[ indexFromName( name )].field; }
232232

233233
//! Get field's origin (value from an enumeration)
234-
FieldOrigin fieldOrigin( int fieldIdx ) const { return mFields[fieldIdx].origin; }
234+
FieldOrigin fieldOrigin( int fieldIdx ) const;
235235
//! Get field's origin index (its meaning is specific to each type of origin)
236236
int fieldOriginIndex( int fieldIdx ) const { return mFields[fieldIdx].originIndex; }
237237

@@ -261,6 +261,7 @@ class CORE_EXPORT QgsFields
261261

262262
//! map for quick resolution of name to index
263263
QHash<QString, int> mNameToIndex;
264+
264265
};
265266

266267

src/core/qgsmaprenderer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ void QgsMapRenderer::adjustExtentToSize()
175175
if ( !myWidth || !myHeight )
176176
{
177177
mScale = 1.0;
178-
newCoordXForm.setParameters( 0, 0, 0, 0 );
178+
newCoordXForm.setParameters( 1, 0, 0, 0 );
179179
return;
180180
}
181181

src/core/qgsmessageoutput.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ QgsMessageOutput::~QgsMessageOutput()
4747

4848
QgsMessageOutputConsole::QgsMessageOutputConsole()
4949
: mMessage( "" )
50+
, mMsgType( MessageText )
5051
{
5152
}
5253

src/core/qgsvectorlayer.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -2091,6 +2091,9 @@ void QgsVectorLayer::addAttributeEditorWidget( QgsAttributeEditorElement* data )
20912091

20922092
const QString QgsVectorLayer::editorWidgetV2( int fieldIdx ) const
20932093
{
2094+
if ( fieldIdx < 0 || fieldIdx >= mUpdatedFields.count() )
2095+
return "TextEdit";
2096+
20942097
return mEditorWidgetV2Types.value( mUpdatedFields[fieldIdx].name(), "TextEdit" );
20952098
}
20962099

src/core/raster/qgshuesaturationfilter.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@
2525
QgsHueSaturationFilter::QgsHueSaturationFilter( QgsRasterInterface* input )
2626
: QgsRasterInterface( input ),
2727
mSaturation( 0 ),
28+
mSaturationScale( 1 ),
2829
mGrayscaleMode( QgsHueSaturationFilter::GrayscaleOff ),
2930
mColorizeOn( false ),
3031
mColorizeColor( QColor::fromRgb( 255, 128, 128 ) ),
32+
mColorizeH( 0 ),
33+
mColorizeS( 50 ),
3134
mColorizeStrength( 100 )
3235
{
3336
}

src/core/raster/qgsrasterblock.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ QGis::DataType QgsRasterBlock::typeWithNoDataValue( QGis::DataType dataType, dou
261261
case QGis::Float64:
262262
*noDataValue = std::numeric_limits<double>::max() * -1.0;
263263
newDataType = QGis::Float64;
264+
break;
264265
default:
265266
QgsDebugMsg( QString( "Unknow data type %1" ).arg( dataType ) );
266267
return QGis::UnknownDataType;

src/core/symbology-ng/qgscptcityarchive.cpp

+7-24
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ QMap< QString, QStringList > QgsCptCityDirectoryItem::rampsMap()
984984
curName = schemeName;
985985
curVariant = "";
986986

987-
// stupid code to find if name ends with 1-3 digit number - should use regexp
987+
// find if name ends with 1-3 digit number
988988
// TODO need to detect if ends with b/c also
989989
if ( schemeName.length() > 1 && schemeName.endsWith( "a" ) && ! listVariant.isEmpty() &&
990990
(( prevName + listVariant.last() + "a" ) == curName ) )
@@ -994,32 +994,15 @@ QMap< QString, QStringList > QgsCptCityDirectoryItem::rampsMap()
994994
}
995995
else
996996
{
997-
num = schemeName.right( 3 ).toInt( &ok );
998-
Q_UNUSED( num );
999-
if ( ok )
997+
QRegExp rxVariant( "^(.*[^\\d])(\\d{1,3})$" );
998+
int pos = rxVariant.indexIn( schemeName );
999+
if ( pos > -1 )
10001000
{
1001-
curName = schemeName.left( schemeName.size() - 3 );
1002-
curVariant = schemeName.right( 3 );
1003-
}
1004-
else
1005-
{
1006-
num = schemeName.right( 2 ).toInt( &ok );
1007-
if ( ok )
1008-
{
1009-
curName = schemeName.left( schemeName.size() - 2 );
1010-
curVariant = schemeName.right( 2 );
1011-
}
1012-
else
1013-
{
1014-
num = schemeName.right( 1 ).toInt( &ok );
1015-
if ( ok )
1016-
{
1017-
curName = schemeName.left( schemeName.size() - 1 );
1018-
curVariant = schemeName.right( 1 );
1019-
}
1020-
}
1001+
curName = rxVariant.cap( 1 );
1002+
curVariant = rxVariant.cap( 2 );
10211003
}
10221004
}
1005+
10231006
curSep = curName.right( 1 );
10241007
if ( curSep == "-" || curSep == "_" )
10251008
{

src/core/symbology-ng/qgsfillsymbollayerv2.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,14 @@ void QgsShapeburstFillSymbolLayerV2::dtArrayToQImage( double * array, QImage *im
14371437
squaredVal = array[idx];
14381438

14391439
//scale result to fit in the range [0, 1]
1440-
pixVal = squaredVal > 0 ? qMin(( sqrt( squaredVal ) / maxDistanceValue ), 1.0 ) : 0;
1440+
if ( maxDistanceValue > 0 )
1441+
{
1442+
pixVal = squaredVal > 0 ? qMin(( sqrt( squaredVal ) / maxDistanceValue ), 1.0 ) : 0;
1443+
}
1444+
else
1445+
{
1446+
pixVal = 1.0;
1447+
}
14411448

14421449
//convert value to color from ramp
14431450
pixColor = ramp->color( pixVal );

src/core/symbology-ng/qgsheatmaprenderer.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,17 @@
3131

3232
QgsHeatmapRenderer::QgsHeatmapRenderer( )
3333
: QgsFeatureRendererV2( "heatmapRenderer" )
34+
, mCalculatedMaxValue( 0 )
3435
, mRadius( 10 )
36+
, mRadiusPixels( 0 )
37+
, mRadiusSquared( 0 )
3538
, mRadiusUnit( QgsSymbolV2::MM )
39+
, mWeightAttrNum( -1 )
3640
, mGradientRamp( 0 )
3741
, mInvertRamp( false )
3842
, mExplicitMax( 0.0 )
3943
, mRenderQuality( 1 )
44+
, mFeaturesRendered( 0 )
4045
{
4146
mGradientRamp = new QgsVectorGradientColorRampV2( QColor( 255, 255, 255 ), QColor( 0, 0, 0 ) );
4247

src/gui/attributetable/qgsdualview.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,11 @@ void QgsDualView::columnBoxInit()
154154

155155
Q_FOREACH ( const QgsField& field, fields )
156156
{
157-
if ( mLayerCache->layer()->editorWidgetV2( mLayerCache->layer()->fieldNameIndex( field.name() ) ) != "Hidden" )
157+
int fieldIndex = mLayerCache->layer()->fieldNameIndex( field.name() );
158+
if ( fieldIndex == -1 )
159+
continue;
160+
161+
if ( mLayerCache->layer()->editorWidgetV2( fieldIndex ) != "Hidden" )
158162
{
159163
QIcon icon = QgsApplication::getThemeIcon( "/mActionNewAttribute.png" );
160164
QString text = field.name();

src/gui/qgsattributeform.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@ void QgsAttributeForm::init()
421421
Q_FOREACH ( const QgsField& field, mLayer->pendingFields().toList() )
422422
{
423423
int idx = mLayer->fieldNameIndex( field.name() );
424+
if ( idx < 0 )
425+
continue;
426+
424427
//show attribute alias if available
425428
QString fieldName = mLayer->attributeDisplayName( idx );
426429

src/gui/qgscomposerruler.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ void QgsComposerRuler::drawRotatedText( QPainter *painter, QPointF pos, const QS
234234

235235
void QgsComposerRuler::drawSmallDivisions( QPainter *painter, double startPos, int numDivisions, double rulerScale, double maxPos )
236236
{
237+
if ( numDivisions == 0 )
238+
return;
239+
237240
//draw small divisions starting at startPos (in mm)
238241
double smallMarkerPos = startPos;
239242
double smallDivisionSpacing = rulerScale / numDivisions;

src/gui/qgscomposerview.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949

5050
QgsComposerView::QgsComposerView( QWidget* parent, const char* name, Qt::WindowFlags f )
5151
: QGraphicsView( parent )
52+
, mCurrentTool( Select )
53+
, mPreviousTool( Select )
5254
, mRubberBandItem( 0 )
5355
, mRubberBandLineItem( 0 )
5456
, mMoveContentItem( 0 )

src/gui/qgsexpressionbuilderwidget.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ void QgsExpressionBuilderWidget::fillFieldValues( int fieldIndex, int countLimit
274274

275275
// TODO We should thread this so that we don't hold the user up if the layer is massive.
276276
mValueListWidget->clear();
277+
278+
if ( fieldIndex < 0 )
279+
return;
280+
277281
mValueListWidget->setUpdatesEnabled( false );
278282
mValueListWidget->blockSignals( true );
279283

@@ -566,6 +570,7 @@ void QgsExpressionBuilderWidget::loadSampleValues()
566570

567571
mValueGroupBox->show();
568572
int fieldIndex = mLayer->fieldNameIndex( item->text() );
573+
569574
fillFieldValues( fieldIndex, 10 );
570575
}
571576

src/gui/qgsidentifymenu.h

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class GUI_EXPORT QgsIdentifyMenu : public QMenu
4848
, mAllResults( false )
4949
, mIsExternalAction( false )
5050
, mLayer( NULL )
51+
, mFeatureId( 0 )
5152
, mLevel( LayerLevel )
5253
, mMapLayerAction( NULL )
5354
{}
@@ -57,6 +58,7 @@ class GUI_EXPORT QgsIdentifyMenu : public QMenu
5758
, mAllResults( layer == 0 )
5859
, mIsExternalAction( mapLayerAction != 0 )
5960
, mLayer( layer )
61+
, mFeatureId( 0 )
6062
, mLevel( LayerLevel )
6163
, mMapLayerAction( mapLayerAction )
6264
{}

src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,10 @@ QgsRendererRulePropsDialog::QgsRendererRulePropsDialog( QgsRuleBasedRendererV2::
581581
{
582582
groupScale->setChecked( true );
583583
// caution: rule uses scale denom, scale widget uses true scales
584-
mScaleRangeWidget->setMaximumScale( 1.0 / rule->scaleMinDenom() );
585-
mScaleRangeWidget->setMinimumScale( 1.0 / rule->scaleMaxDenom() );
584+
if ( rule->scaleMinDenom() > 0 )
585+
mScaleRangeWidget->setMaximumScale( 1.0 / rule->scaleMinDenom() );
586+
if ( rule->scaleMaxDenom() > 0 )
587+
mScaleRangeWidget->setMinimumScale( 1.0 / rule->scaleMaxDenom() );
586588
}
587589

588590
if ( mRule->symbol() )

src/plugins/heatmap/heatmap.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ double Heatmap::quarticKernel( const double distance, const int bandwidth, const
444444
case Heatmap::Scaled:
445445
{
446446
// Normalizing constant
447-
double k = outputType == Heatmap::Scaled ? 116. / ( 5. * M_PI * pow(( double )bandwidth, 2 ) ) : 1.0;
447+
double k = 116. / ( 5. * M_PI * pow(( double )bandwidth, 2 ) );
448448

449449
// Derived from Wand and Jones (1995), p. 175
450450
return k * ( 15. / 16. ) * pow( 1. - pow( distance / ( double )bandwidth, 2 ), 2 );
@@ -461,7 +461,7 @@ double Heatmap::triweightKernel( const double distance, const int bandwidth, con
461461
case Heatmap::Scaled:
462462
{
463463
// Normalizing constant
464-
double k = outputType == Heatmap::Scaled ? 128. / ( 35. * M_PI * pow(( double )bandwidth, 2 ) ) : 1.0;
464+
double k = 128. / ( 35. * M_PI * pow(( double )bandwidth, 2 ) );
465465

466466
// Derived from Wand and Jones (1995), p. 175
467467
return k * ( 35. / 32. ) * pow( 1. - pow( distance / ( double )bandwidth, 2 ), 3 );
@@ -478,7 +478,7 @@ double Heatmap::epanechnikovKernel( const double distance, const int bandwidth,
478478
case Heatmap::Scaled:
479479
{
480480
// Normalizing constant
481-
double k = outputType == Heatmap::Scaled ? 8. / ( 3. * M_PI * pow(( double )bandwidth, 2 ) ) : 1.0;
481+
double k = 8. / ( 3. * M_PI * pow(( double )bandwidth, 2 ) );
482482

483483
// Derived from Wand and Jones (1995), p. 175
484484
return k * ( 3. / 4. ) * ( 1. - pow( distance / ( double )bandwidth, 2 ) );

0 commit comments

Comments
 (0)