Skip to content

Commit

Permalink
Coverity fixes
Browse files Browse the repository at this point in the history
Including a notable bug causing "mean" to be missing from merge
attributes dialog options.
  • Loading branch information
nyalldawson committed Feb 9, 2015
1 parent a1b858b commit e425372
Show file tree
Hide file tree
Showing 28 changed files with 144 additions and 73 deletions.
13 changes: 7 additions & 6 deletions src/analysis/interpolation/Bezier3D.cc
Expand Up @@ -81,21 +81,22 @@ void Bezier3D::calcSecDer( float t, Vector3D* v )
v->setY( 0 );
v->setZ( 0 );

if ( mControlPoly->count() < 3 )
int nodes = mControlPoly->count();
if ( nodes < 3 )
{
return;
}

for ( int n = 1; n <= int( mControlPoly->count() - 2 ); n++ )
for ( int n = 1; n <= int( nodes - 2 ); n++ )
{
double bernst = MathUtils::calcBernsteinPoly( mControlPoly->count() - 3, n - 1, t );
double bernst = MathUtils::calcBernsteinPoly( nodes - 3, n - 1, t );
v->setX( v->getX() + (( *mControlPoly )[n+1]->getX() - 2*( *mControlPoly )[n]->getX() + ( *mControlPoly )[n-1]->getX() )*bernst );
v->setY( v->getY() + (( *mControlPoly )[n+1]->getY() - 2*( *mControlPoly )[n]->getY() + ( *mControlPoly )[n-1]->getY() )*bernst );
v->setZ( v->getZ() + (( *mControlPoly )[n+1]->getZ() - 2*( *mControlPoly )[n]->getZ() + ( *mControlPoly )[n-1]->getZ() )*bernst );
}
v->setX( v->getX()*MathUtils::faculty( mControlPoly->count() - 1 ) / MathUtils::faculty( mControlPoly->count() - 3 ) );
v->setY( v->getY()*MathUtils::faculty( mControlPoly->count() - 1 ) / MathUtils::faculty( mControlPoly->count() - 3 ) );
v->setZ( v->getZ()*MathUtils::faculty( mControlPoly->count() - 1 ) / MathUtils::faculty( mControlPoly->count() - 3 ) );
v->setX( v->getX()*MathUtils::faculty( nodes - 1 ) / MathUtils::faculty( nodes - 3 ) );
v->setY( v->getY()*MathUtils::faculty( nodes - 1 ) / MathUtils::faculty( nodes - 3 ) );
v->setZ( v->getZ()*MathUtils::faculty( nodes - 1 ) / MathUtils::faculty( nodes - 3 ) );
}

else
Expand Down
51 changes: 44 additions & 7 deletions src/analysis/interpolation/CloughTocherInterpolator.cc
Expand Up @@ -17,11 +17,53 @@
#include "CloughTocherInterpolator.h"
#include "qgslogger.h"

#include <cmath>
#include <qmath.h>

CloughTocherInterpolator::CloughTocherInterpolator()
: mTIN( 0 )
, mEdgeTolerance( 0.00001 )
, der1X( 0.0 )
, der1Y( 0.0 )
, der2X( 0.0 )
, der2Y( 0.0 )
, der3X( 0.0 )
, der3Y( 0.0 )
{

}

CloughTocherInterpolator::CloughTocherInterpolator( NormVecDecorator* tin )
: mTIN( tin )
, mEdgeTolerance( 0.00001 )
, der1X( 0.0 )
, der1Y( 0.0 )
, der2X( 0.0 )
, der2Y( 0.0 )
, der3X( 0.0 )
, der3Y( 0.0 )
{

}

CloughTocherInterpolator::~CloughTocherInterpolator()
{
//nothing to do
}

void CloughTocherInterpolator::setTriangulation( NormVecDecorator* tin )
{
mTIN = tin;
}

double CloughTocherInterpolator::calcBernsteinPoly( int n, int i, int j, int k, double u, double v, double w )
{
double result = MathUtils::faculty( n ) * MathUtils::power( u, i ) * MathUtils::power( v, j ) * MathUtils::power( w, k ) / ( MathUtils::faculty( i ) * MathUtils::faculty( j ) * MathUtils::faculty( k ) );
if ( i < 0 || j < 0 || k < 0 )
{
QgsDebugMsg( "Invalid parameters for Bernstein poly calculation!" );
return 0;
}

double result = MathUtils::faculty( n ) * qPow( u, i ) * qPow( v, j ) * qPow( w, k ) / ( MathUtils::faculty( i ) * MathUtils::faculty( j ) * MathUtils::faculty( k ) );
return result;
}

Expand Down Expand Up @@ -728,8 +770,3 @@ void CloughTocherInterpolator::init( double x, double y )//version which has uni
#endif







21 changes: 0 additions & 21 deletions src/analysis/interpolation/CloughTocherInterpolator.h
Expand Up @@ -91,27 +91,6 @@ class ANALYSIS_EXPORT CloughTocherInterpolator : public TriangleInterpolator
virtual void setTriangulation( NormVecDecorator* tin );
};


inline CloughTocherInterpolator::CloughTocherInterpolator() : mTIN( 0 ), mEdgeTolerance( 0.00001 )
{

}

inline CloughTocherInterpolator::CloughTocherInterpolator( NormVecDecorator* tin ) : mTIN( tin ), mEdgeTolerance( 0.00001 )
{

}

inline CloughTocherInterpolator::~CloughTocherInterpolator()
{
//nothing to do
}

inline void CloughTocherInterpolator::setTriangulation( NormVecDecorator* tin )
{
mTIN = tin;
}

#endif


Expand Down
3 changes: 2 additions & 1 deletion src/analysis/interpolation/MathUtils.cc
Expand Up @@ -16,6 +16,7 @@

#include "MathUtils.h"
#include "qgslogger.h"
#include <qmath.h>

bool MathUtils::calcBarycentricCoordinates( double x, double y, Point3D* p1, Point3D* p2, Point3D* p3, Point3D* result )
{
Expand Down Expand Up @@ -104,7 +105,7 @@ double MathUtils::calcBernsteinPoly( int n, int i, double t )
return 0;
}

return lower( n, i )*power( t, i )*power(( 1 - t ), ( n - i ) );
return lower( n, i )*qPow( t, i )*qPow(( 1 - t ), ( n - i ) );
}

double MathUtils::cFDerBernsteinPoly( int n, int i, double t )
Expand Down
16 changes: 13 additions & 3 deletions src/analysis/interpolation/qgsgridfilewriter.cpp
Expand Up @@ -23,13 +23,23 @@
#include <QProgressDialog>

QgsGridFileWriter::QgsGridFileWriter( QgsInterpolator* i, QString outputPath, QgsRectangle extent, int nCols, int nRows, double cellSizeX, double cellSizeY )
: mInterpolator( i ), mOutputFilePath( outputPath ), mInterpolationExtent( extent ), mNumColumns( nCols ), mNumRows( nRows )
, mCellSizeX( cellSizeX ), mCellSizeY( cellSizeY )
: mInterpolator( i )
, mOutputFilePath( outputPath )
, mInterpolationExtent( extent )
, mNumColumns( nCols )
, mNumRows( nRows )
, mCellSizeX( cellSizeX )
, mCellSizeY( cellSizeY )
{

}

QgsGridFileWriter::QgsGridFileWriter(): mInterpolator( 0 )
QgsGridFileWriter::QgsGridFileWriter()
: mInterpolator( 0 )
, mNumColumns( 0 )
, mNumRows( 0 )
, mCellSizeX( 0 )
, mCellSizeY( 0 )
{

}
Expand Down
5 changes: 4 additions & 1 deletion src/analysis/interpolation/qgsinterpolator.cpp
Expand Up @@ -20,12 +20,15 @@
#include "qgsvectorlayer.h"
#include "qgsgeometry.h"

QgsInterpolator::QgsInterpolator( const QList<LayerData>& layerData ): mDataIsCached( false ), mLayerData( layerData )
QgsInterpolator::QgsInterpolator( const QList<LayerData>& layerData )
: mDataIsCached( false )
, mLayerData( layerData )
{

}

QgsInterpolator::QgsInterpolator()
: mDataIsCached( false )
{

}
Expand Down
2 changes: 2 additions & 0 deletions src/analysis/network/qgsgraph.cpp
Expand Up @@ -83,6 +83,8 @@ int QgsGraph::findVertex( const QgsPoint& pt ) const
}

QgsGraphArc::QgsGraphArc()
: mOut( 0 )
, mIn( 0 )
{

}
Expand Down
3 changes: 3 additions & 0 deletions src/analysis/raster/qgsrastercalcnode.cpp
Expand Up @@ -20,6 +20,7 @@ QgsRasterCalcNode::QgsRasterCalcNode()
, mLeft( 0 )
, mRight( 0 )
, mNumber( 0 )
, mOperator( opPLUS ) //not used
{
}

Expand All @@ -28,6 +29,7 @@ QgsRasterCalcNode::QgsRasterCalcNode( double number )
, mLeft( 0 )
, mRight( 0 )
, mNumber( number )
, mOperator( opPLUS ) //not used
{
}

Expand All @@ -46,6 +48,7 @@ QgsRasterCalcNode::QgsRasterCalcNode( const QString& rasterName )
, mRight( 0 )
, mNumber( 0 )
, mRasterName( rasterName )
, mOperator( opPLUS ) //not used
{
}

Expand Down
2 changes: 2 additions & 0 deletions src/analysis/raster/qgsrastercalculator.cpp
Expand Up @@ -250,6 +250,8 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
}

QgsRasterCalculator::QgsRasterCalculator()
: mNumOutputColumns( 0 )
, mNumOutputRows( 0 )
{
}

Expand Down
6 changes: 5 additions & 1 deletion src/analysis/raster/qgsrastermatrix.cpp
Expand Up @@ -20,7 +20,11 @@

#include <cmath>

QgsRasterMatrix::QgsRasterMatrix(): mColumns( 0 ), mRows( 0 ), mData( 0 )
QgsRasterMatrix::QgsRasterMatrix()
: mColumns( 0 )
, mRows( 0 )
, mData( 0 )
, mNodataValue( -1 )
{
}

Expand Down
11 changes: 9 additions & 2 deletions src/analysis/raster/qgsrelief.cpp
Expand Up @@ -33,8 +33,15 @@
#define TO8F(x) QFile::encodeName( x ).constData()
#endif

QgsRelief::QgsRelief( const QString& inputFile, const QString& outputFile, const QString& outputFormat ): \
mInputFile( inputFile ), mOutputFile( outputFile ), mOutputFormat( outputFormat ), mZFactor( 1.0 )
QgsRelief::QgsRelief( const QString& inputFile, const QString& outputFile, const QString& outputFormat )
: mInputFile( inputFile )
, mOutputFile( outputFile )
, mOutputFormat( outputFormat )
, mCellSizeX( 0.0 )
, mCellSizeY( 0.0 )
, mInputNodataValue( -1 )
, mOutputNodataValue( -1 )
, mZFactor( 1.0 )
{
mSlopeFilter = new QgsSlopeFilter( inputFile, outputFile, outputFormat );
mAspectFilter = new QgsAspectFilter( inputFile, outputFile, outputFormat );
Expand Down
3 changes: 1 addition & 2 deletions src/analysis/vector/qgstransectsample.cpp
Expand Up @@ -146,9 +146,8 @@ int QgsTransectSample::createSample( QProgressDialog* pd )
}

//find baseline for strata
bool strataIdOk = true;
QVariant strataId = fet.attribute( mStrataIdAttribute );
QgsGeometry* baselineGeom = findBaselineGeometry( strataIdOk ? strataId : -1 );
QgsGeometry* baselineGeom = findBaselineGeometry( strataId.isValid() ? strataId : -1 );
if ( !baselineGeom )
{
continue;
Expand Down
1 change: 1 addition & 0 deletions src/analysis/vector/qgszonalstatistics.cpp
Expand Up @@ -43,6 +43,7 @@ QgsZonalStatistics::QgsZonalStatistics( QgsVectorLayer* polygonLayer, const QStr
QgsZonalStatistics::QgsZonalStatistics()
: mRasterBand( 0 )
, mPolygonLayer( 0 )
, mInputNodataValue( -1 )
{

}
Expand Down
6 changes: 1 addition & 5 deletions src/app/composer/qgscomposerpicturewidget.cpp
Expand Up @@ -486,7 +486,7 @@ int QgsComposerPictureWidget::addDirectoryToPreview( const QString& path )
QIcon icon( filePath );
listItem->setIcon( icon );
}
else if ( fileIsPixel ) //for pixel formats: create icon from scaled pixmap
else //for pixel formats: create icon from scaled pixmap
{
QPixmap iconPixmap( filePath );
if ( iconPixmap.isNull() )
Expand All @@ -498,10 +498,6 @@ int QgsComposerPictureWidget::addDirectoryToPreview( const QString& path )
QIcon icon( scaledPixmap );
listItem->setIcon( icon );
}
else
{
++counter; continue;
}

listItem->setText( "" );
//store the absolute icon file path as user data
Expand Down
10 changes: 5 additions & 5 deletions src/app/composer/qgscomposerscalebarwidget.cpp
Expand Up @@ -104,12 +104,12 @@ void QgsComposerScaleBarWidget::refreshMapComboBox()
mMapComboBox->addItem( tr( "Map %1" ).arg(( *mapItemIt )->id() ) );
}
}
}

if ( saveCurrentComboText.isEmpty() && mComposerScaleBar->composerMap() )
{
//combo box was not initialised before
mMapComboBox->setCurrentIndex( mMapComboBox->findText( tr( "Map %1" ).arg( mComposerScaleBar->composerMap()->id() ) ) );
if ( saveCurrentComboText.isEmpty() && mComposerScaleBar->composerMap() )
{
//combo box was not initialised before
mMapComboBox->setCurrentIndex( mMapComboBox->findText( tr( "Map %1" ).arg( mComposerScaleBar->composerMap()->id() ) ) );
}
}
if ( mMapComboBox->findText( saveCurrentComboText ) == -1 )
{
Expand Down
4 changes: 4 additions & 0 deletions src/app/composer/qgscompositionwidget.cpp
Expand Up @@ -527,6 +527,10 @@ void QgsCompositionWidget::on_mPageStyleButton_clicked()
}

QgsFillSymbolV2* newSymbol = dynamic_cast<QgsFillSymbolV2*>( mComposition->pageStyleSymbol()->clone() );
if ( !newSymbol )
{
newSymbol = new QgsFillSymbolV2();
}
QgsSymbolV2SelectorDialog d( newSymbol, QgsStyleV2::defaultStyle(), coverageLayer );

if ( d.exec() == QDialog::Accepted )
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsdecorationgrid.cpp
Expand Up @@ -828,7 +828,7 @@ bool QgsDecorationGrid::getIntervalFromCurrentLayer( double* values )
return false;
}
QgsRasterLayer* rlayer = dynamic_cast<QgsRasterLayer*>( layer );
if ( !rlayer )
if ( !rlayer || rlayer->width() == 0 || rlayer->height() == 0 )
{
QMessageBox::warning( 0, tr( "Error" ), tr( "Invalid raster layer" ) );
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgslabelpreview.cpp
Expand Up @@ -26,7 +26,7 @@ QgsLabelPreview::QgsLabelPreview( QWidget* parent )

// construct a device-based render context
QgsMapToPixel newCoordXForm;
newCoordXForm.setParameters( 0, 0, 0, 0 );
newCoordXForm.setParameters( 1, 0, 0, 0 );
mContext = new QgsRenderContext();
mContext->setMapToPixel( newCoordXForm );
}
Expand Down
5 changes: 1 addition & 4 deletions src/app/qgsmergeattributesdialog.cpp
Expand Up @@ -159,15 +159,12 @@ QComboBox *QgsMergeAttributesDialog::createMergeComboBox( QVariant::Type columnT
newComboBox->addItem( tr( "Maximum" ), "maximum" );
newComboBox->addItem( tr( "Median" ), "median" );
newComboBox->addItem( tr( "Sum" ), "sum" );
newComboBox->addItem( tr( "Mean" ), "mean" );
}
else if ( columnType == QVariant::String )
{
newComboBox->addItem( tr( "Concatenation" ), "concat" );
}
else if ( columnType == QVariant::Double )
{
newComboBox->addItem( tr( "Mean" ), "mean" );
}

newComboBox->addItem( tr( "Skip attribute" ), "skip" );

Expand Down
14 changes: 11 additions & 3 deletions src/core/composer/qgsaddremovemultiframecommand.cpp
Expand Up @@ -21,12 +21,20 @@
#include "qgsproject.h"


QgsAddRemoveMultiFrameCommand::QgsAddRemoveMultiFrameCommand( State s, QgsComposerMultiFrame* multiFrame, QgsComposition* c, const QString& text, QUndoCommand* parent ):
QUndoCommand( text, parent ), mMultiFrame( multiFrame ), mComposition( c ), mState( s ), mFirstRun( true )
QgsAddRemoveMultiFrameCommand::QgsAddRemoveMultiFrameCommand( State s, QgsComposerMultiFrame* multiFrame, QgsComposition* c, const QString& text, QUndoCommand* parent )
: QUndoCommand( text, parent )
, mMultiFrame( multiFrame )
, mComposition( c )
, mState( s )
, mFirstRun( true )
{
}

QgsAddRemoveMultiFrameCommand::QgsAddRemoveMultiFrameCommand(): mMultiFrame( 0 ), mComposition( 0 )
QgsAddRemoveMultiFrameCommand::QgsAddRemoveMultiFrameCommand()
: mMultiFrame( 0 )
, mComposition( 0 )
, mState( Added )
, mFirstRun( true )
{
}

Expand Down
1 change: 1 addition & 0 deletions src/core/composer/qgscomposerhtml.cpp
Expand Up @@ -97,6 +97,7 @@ QgsComposerHtml::QgsComposerHtml()
, mExpressionFeature( 0 )
, mExpressionLayer( 0 )
, mDistanceArea( 0 )
, mEnableUserStylesheet( false )
, mFetcher( 0 )
{
mDistanceArea = new QgsDistanceArea();
Expand Down
1 change: 1 addition & 0 deletions src/core/composer/qgscomposerlegend.cpp
Expand Up @@ -50,6 +50,7 @@ QgsComposerLegend::QgsComposerLegend()
, mLegendModel2( 0 )
, mCustomLayerTree( 0 )
, mComposerMap( 0 )
, mLegendFilterByMap( false )
{

}
Expand Down

0 comments on commit e425372

Please sign in to comment.