Commit 25058c30 authored by Sean McBride's avatar Sean McBride
Browse files

Fixed various warnings from new cppcheck 1.78

Types of warnings:
- mismatch between parameters names in declaration vs definition
- make certain parameters references, or const references
- checking array index after its use
- prefer preincrement
- change return type of operator=

There are some very minor API chages here (const/reference).
parent fb3e928f
......@@ -13,7 +13,7 @@
//=========================================================================
// This file contains enough suppressions to result in no cppcheck warnings,
// at least on macOS with cppcheck 1.77.
// at least on macOS with cppcheck 1.78.
// To run:
// cd /path/to/VTK/
......@@ -64,6 +64,7 @@ argumentSize
// False positives.
AssignmentAddressToInteger:Common/Math/vtkPolynomialSolversUnivariate.cxx
AssignmentAddressToInteger:IO/Exodus/vtkExodusIIReader.cxx
CastIntegerToAddressAtReturn:Geovis/Core/vtkGeoTreeNode.h
copyCtorPointerCopying:IO/NetCDF/vtkSLACReader.cxx
duplicateExpression:Rendering/Annotation/vtkScalarBarActor.cxx
......@@ -118,6 +119,9 @@ invalidPointerCast:Rendering/OpenGL2/vtkOpenGLSphereMapper.cxx
invalidPointerCast:Rendering/OpenGL2/vtkOpenGLStickMapper.cxx
invalidPointerCast:Rendering/OpenGL2/vtkOpenGLVertexBufferObject.cxx
invalidPointerCast:Rendering/ParallelLIC/vtkParallelTimer.cxx
// 14 warnings
copyCtorAndEqOperator
// 6 warnings
noConstructor:Common/Core/Testing/Cxx/TestCxxFeatures.cxx
noConstructor:Common/Core/Testing/Cxx/TestDataArrayIterators.cxx
......
......@@ -42,7 +42,7 @@ public:
void Set(vtkObject *object);
/**
* Get the vtkObject pointer or nullptr is the object has been collected.
* Get the vtkObject pointer or nullptr if the object has been collected.
*/
vtkObject* Get();
......
......@@ -2060,13 +2060,13 @@ int vtkPolynomialSolversUnivariate::SolveCubic( double c0, double c1, double c2,
}
//----------------------------------------------------------------------------
// Solves a quadratic equation c1*t^2 + c2*t + c3 = 0 when c1, c2, and
// c3 are REAL. Solution is motivated by Numerical Recipes In C 2nd
// Solves a quadratic equation c0*t^2 + c1*t + c2 = 0 when c0, c1, and
// c2 are REAL. Solution is motivated by Numerical Recipes In C 2nd
// Ed. Return array contains number of (real) roots (counting
// multiple roots as one) followed by roots themselves. Note that
// roots[3] contains a return code further describing solution - see
// documentation for SolveCubic() for meaining of return codes.
double* vtkPolynomialSolversUnivariate::SolveQuadratic( double c1, double c2, double c3)
double* vtkPolynomialSolversUnivariate::SolveQuadratic( double c0, double c1, double c2)
{
static double roots[4];
roots[0] = 0.0;
......@@ -2074,36 +2074,36 @@ double* vtkPolynomialSolversUnivariate::SolveQuadratic( double c1, double c2, do
roots[2] = 0.0;
int num_roots;
roots[3] = vtkPolynomialSolversUnivariate::SolveQuadratic( c1, c2, c3, &roots[1], &roots[2],
roots[3] = vtkPolynomialSolversUnivariate::SolveQuadratic( c0, c1, c2, &roots[1], &roots[2],
&num_roots );
roots[0] = num_roots;
return roots;
}
//----------------------------------------------------------------------------
// Solves A Quadratic Equation c1*t^2 + c2*t + c3 = 0 when
// c1, c2, and c3 are REAL.
// Solves A Quadratic Equation c0*t^2 + c1*t + c2 = 0 when
// c0, c1, and c2 are REAL.
// Solution is motivated by Numerical Recipes In C 2nd Ed.
// Roots and number of roots are stored in user provided variables
// r1, r2, num_roots
int vtkPolynomialSolversUnivariate::SolveQuadratic( double c1, double c2, double c3,
int vtkPolynomialSolversUnivariate::SolveQuadratic( double c0, double c1, double c2,
double *r1, double *r2, int *num_roots )
{
double Q;
double determinant;
// Quadratic equation: c1*t^2 + c2*t + c3 = 0
// Quadratic equation: c0*t^2 + c1*t + c2 = 0
// Make sure this is a quadratic equation
if( c1 != 0.0 )
if( c0 != 0.0 )
{
determinant = c2*c2 - 4*c1*c3;
determinant = c1*c1 - 4*c0*c2;
if( determinant >= 0.0 )
{
Q = -0.5 * (c2 + VTK_SIGN(c2)*sqrt(determinant));
Q = -0.5 * (c1 + VTK_SIGN(c1)*sqrt(determinant));
*r1 = Q / c1;
*r1 = Q / c0;
if( Q == 0.0 )
{
......@@ -2111,7 +2111,7 @@ int vtkPolynomialSolversUnivariate::SolveQuadratic( double c1, double c2, double
}
else
{
*r2 = c3 / Q;
*r2 = c2 / Q;
}
*num_roots = 2;
......@@ -2130,10 +2130,10 @@ int vtkPolynomialSolversUnivariate::SolveQuadratic( double c1, double c2, double
}
}
else // Linear Equation: c2*t + c3 = 0
else // Linear Equation: c1*t + c2 = 0
{
// Okay this was not quadratic - lets try linear
return vtkPolynomialSolversUnivariate::SolveLinear( c2, c3, r1, num_roots );
return vtkPolynomialSolversUnivariate::SolveLinear( c1, c2, r1, num_roots );
}
}
......
......@@ -214,7 +214,7 @@ public:
static double* SolveCubic(double c0, double c1, double c2, double c3);
/**
* Solves a quadratic equation c1*t^2 + c2*t + c3 = 0 when c1, c2, and c3
* Solves a quadratic equation c0*t^2 + c1*t + c2 = 0 when c0, c1, and c2
* are REAL. Solution is motivated by Numerical Recipes In C 2nd Ed.
* Return array contains number of (real) roots (counting multiple roots as
* one) followed by roots themselves. Note that roots[3] contains a return
......@@ -224,7 +224,7 @@ public:
static double* SolveQuadratic(double c0, double c1, double c2);
/**
* Solves a linear equation c2*t + c3 = 0 when c2 and c3 are REAL.
* Solves a linear equation c0*t + c1 = 0 when c0 and c1 are REAL.
* Solution is motivated by Numerical Recipes In C 2nd Ed.
* Return array contains number of roots followed by roots themselves.
*/
......@@ -247,8 +247,8 @@ public:
double *r1, double *r2, double *r3, int *num_roots);
/**
* Solves a quadratic equation c1*t^2 + c2*t + c3 = 0 when
* c1, c2, and c3 are REAL.
* Solves a quadratic equation c0*t^2 + c1*t + c2 = 0 when
* c0, c1, and c2 are REAL.
* Solution is motivated by Numerical Recipes In C 2nd Ed.
* Roots and number of roots are stored in user provided variables
* r1, r2, num_roots
......@@ -266,10 +266,10 @@ public:
static int SolveQuadratic( double* c, double* r, int* m );
/**
* Solves a linear equation c2*t + c3 = 0 when c2 and c3 are REAL.
* Solves a linear equation c0*t + c1 = 0 when c0 and c1 are REAL.
* Solution is motivated by Numerical Recipes In C 2nd Ed.
* Root and number of (real) roots are stored in user provided variables
* r2 and num_roots.
* r1 and num_roots.
*/
static int SolveLinear(double c0, double c1, double *r1, int *num_roots);
......
......@@ -35,7 +35,7 @@ struct TimedQuaternion
{
this->Time = 0.0;
}
TimedQuaternion(double t, vtkQuaterniond q)
TimedQuaternion(double t, const vtkQuaterniond& q)
{
this->Time = t;
this->Q = q;
......
......@@ -24,7 +24,7 @@ double Cell::_R = 10.0;
/*-------------------------------------------------------------------------
-----------------------------------------------------------------------*/
Cell::Cell (int id, vector<Node*> nodes)
Cell::Cell (int id, vector<Node*>& nodes)
{
_refined = false;
_id = id;
......
......@@ -184,7 +184,7 @@ vtkPlane* vtkAMRSliceFilter::GetCutPlane( vtkOverlappingAMR *inp )
//------------------------------------------------------------------------------
vtkUniformGrid* vtkAMRSliceFilter::GetSlice(
double porigin[3], int* dims, double* origin, double* spacing )
double origin[3], int* dims, double* gorigin, double* spacing )
{
// vtkTimerLog::MarkStartEvent( "AMRSlice::GetSliceForBlock" );
......@@ -203,9 +203,9 @@ vtkUniformGrid* vtkAMRSliceFilter::GetSlice(
sliceDims[1] = dims[1];
sliceDims[2] = dims[2];
sliceOrigin[0] = porigin[0];
sliceOrigin[1] = origin[1];
sliceOrigin[2] = origin[2];
sliceOrigin[0] = origin[0];
sliceOrigin[1] = gorigin[1];
sliceOrigin[2] = gorigin[2];
slice->SetOrigin( sliceOrigin );
slice->SetDimensions( sliceDims );
......@@ -218,9 +218,9 @@ vtkUniformGrid* vtkAMRSliceFilter::GetSlice(
sliceDims[1] = 1;
sliceDims[2] = dims[2];
sliceOrigin[0] = origin[0];
sliceOrigin[1] = porigin[1];
sliceOrigin[2] = origin[2];
sliceOrigin[0] = gorigin[0];
sliceOrigin[1] = origin[1];
sliceOrigin[2] = gorigin[2];
slice->SetOrigin( sliceOrigin );
slice->SetDimensions( sliceDims );
......@@ -233,9 +233,9 @@ vtkUniformGrid* vtkAMRSliceFilter::GetSlice(
sliceDims[1] = dims[1];
sliceDims[2] = 1;
sliceOrigin[0] = origin[0];
sliceOrigin[1] = origin[1];
sliceOrigin[2] = porigin[2];
sliceOrigin[0] = gorigin[0];
sliceOrigin[1] = gorigin[1];
sliceOrigin[2] = origin[2];
slice->SetOrigin( sliceOrigin );
slice->SetDimensions( sliceDims );
......
......@@ -239,10 +239,10 @@ class VTKFILTERSCORE_EXPORT vtkStreamingTessellator : public vtkObject
* SetEdgeCallback(), SetTriangleCallback(), and SetTetrahedronCallback()
* with valid values!
*/
void AdaptivelySample3Facet( double* v1, double* v2, double* v3, double* v4 ) const ;
void AdaptivelySample2Facet( double* v1, double* v2, double* v3 ) const ;
void AdaptivelySample1Facet( double* v1, double* v2 ) const ;
void AdaptivelySample0Facet( double* v1 ) const ;
void AdaptivelySample3Facet( double* v0, double* v1, double* v2, double* v3 ) const ;
void AdaptivelySample2Facet( double* v0, double* v1, double* v2 ) const ;
void AdaptivelySample1Facet( double* v0, double* v1 ) const ;
void AdaptivelySample0Facet( double* v0 ) const ;
//@}
//@{
......@@ -334,9 +334,9 @@ class VTKFILTERSCORE_EXPORT vtkStreamingTessellator : public vtkObject
vtkStreamingTessellator();
~vtkStreamingTessellator() VTK_OVERRIDE;
void AdaptivelySample3Facet( double* v1, double* v2, double* v3, double* v4, int maxDepth ) const ;
void AdaptivelySample2Facet( double* v1, double* v2, double* v3, int maxDepth, int move=7 ) const ;
void AdaptivelySample1Facet( double* v1, double* v2, int maxDepth ) const ;
void AdaptivelySample3Facet( double* v0, double* v1, double* v2, double* v3, int maxDepth ) const ;
void AdaptivelySample2Facet( double* v0, double* v1, double* v2, int maxDepth, int move=7 ) const ;
void AdaptivelySample1Facet( double* v0, double* v1, int maxDepth ) const ;
int BestTets( int*, double**, int, int ) const;
......@@ -345,12 +345,12 @@ class VTKFILTERSCORE_EXPORT vtkStreamingTessellator : public vtkObject
void operator = ( const vtkStreamingTessellator& ) VTK_DELETE_FUNCTION;
};
inline void vtkStreamingTessellator::AdaptivelySample3Facet( double* v1, double* v2, double* v3, double* v4 ) const
{ this->AdaptivelySample3Facet( v1, v2, v3, v4, this->MaximumNumberOfSubdivisions ); }
inline void vtkStreamingTessellator::AdaptivelySample2Facet( double* v1, double* v2, double* v3 ) const
{ this->AdaptivelySample2Facet( v1, v2, v3, this->MaximumNumberOfSubdivisions ); }
inline void vtkStreamingTessellator::AdaptivelySample1Facet( double* v1, double* v2 ) const
{ this->AdaptivelySample1Facet( v1, v2, this->MaximumNumberOfSubdivisions ); }
inline void vtkStreamingTessellator::AdaptivelySample3Facet( double* v0, double* v1, double* v2, double* v3 ) const
{ this->AdaptivelySample3Facet( v0, v1, v2, v3, this->MaximumNumberOfSubdivisions ); }
inline void vtkStreamingTessellator::AdaptivelySample2Facet( double* v0, double* v1, double* v2 ) const
{ this->AdaptivelySample2Facet( v0, v1, v2, this->MaximumNumberOfSubdivisions ); }
inline void vtkStreamingTessellator::AdaptivelySample1Facet( double* v0, double* v1 ) const
{ this->AdaptivelySample1Facet( v0, v1, this->MaximumNumberOfSubdivisions ); }
inline int vtkStreamingTessellator::GetEmbeddingDimension( int k ) const
{ if ( k <= 0 || k >= 4 ) return -1; return this->EmbeddingDimension[k]; }
......
......@@ -240,15 +240,17 @@ int vtkAreaContourSpectrumFilter::RequestData(vtkInformation* vtkNotUsed(request
{
samples[i].first = 0;
samples[i].second = 0;
while((scalarValues[pos] < min +
(i+1.0)*((max - min)/((double)NumberOfSamples)))
&&(pos < scalarValues.size()))
double temp = min + (i+1.0)*((max - min)/((double)NumberOfSamples));
while((pos < scalarValues.size()) && (scalarValues[pos] < temp))
{
samples[i].first++;
samples[i].second += areaSignature[pos];
pos++;
}
if(samples[i].first) samples[i].second /= samples[i].first;
if(samples[i].first)
{
samples[i].second /= samples[i].first;
}
}
// no value at the start? put 0
......
......@@ -253,15 +253,17 @@ int vtkVolumeContourSpectrumFilter::RequestData(vtkInformation* vtkNotUsed(reque
{
samples[i].first = 0;
samples[i].second = 0;
while((scalarValues[pos] < min +
(i+1.0)*((max - min)/((double)NumberOfSamples)))
&&(pos < scalarValues.size()))
double temp = min + (i+1.0)*((max - min)/((double)NumberOfSamples));
while((pos < scalarValues.size()) && (scalarValues[pos] < temp))
{
samples[i].first++;
samples[i].second += volumeSignature[pos];
pos++;
}
if(samples[i].first) samples[i].second /= samples[i].first;
if(samples[i].first)
{
samples[i].second /= samples[i].first;
}
}
// no value at the start? put 0
......
......@@ -55,7 +55,7 @@ protected:
~vtkSpherePuzzleArrows() VTK_OVERRIDE;
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) VTK_OVERRIDE;
void AppendArrow(int id0, int id1, vtkPoints *pts, vtkCellArray *polys);
void AppendArrow(int id1, int id2, vtkPoints *pts, vtkCellArray *polys);
int Permutation[32];
......
......@@ -185,7 +185,7 @@ LSDynaFamily::~LSDynaFamily()
}
//-----------------------------------------------------------------------------
void LSDynaFamily::SetDatabaseDirectory( std::string dd )
void LSDynaFamily::SetDatabaseDirectory( const std::string& dd )
{
this->DatabaseDirectory = dd;
}
......@@ -195,7 +195,7 @@ std::string LSDynaFamily::GetDatabaseDirectory()
}
//-----------------------------------------------------------------------------
void LSDynaFamily::SetDatabaseBaseName( std::string bn )
void LSDynaFamily::SetDatabaseBaseName( const std::string& bn )
{
this->DatabaseBaseName = bn;
}
......
......@@ -80,10 +80,10 @@ public:
vtkIdType Offset;
};
void SetDatabaseDirectory( std::string dd );
void SetDatabaseDirectory( const std::string& dd );
std::string GetDatabaseDirectory();
void SetDatabaseBaseName( std::string bn );
void SetDatabaseBaseName( const std::string& bn );
std::string GetDatabaseBaseName();
int ScanDatabaseDirectory();
......
......@@ -70,7 +70,7 @@ public:
{
this->ArrayUnits.clear();
}
void AddUnit(std::string arrayName, std::string unit)
void AddUnit(std::string arrayName, const std::string& unit)
{
this->ArrayUnits[arrayName] = unit;
}
......
......@@ -69,7 +69,7 @@ public:
vtkSetMacro(ReadFromInputString, int);
vtkGetMacro(ReadFromInputString, int);
vtkBooleanMacro(ReadFromInputString, int);
void SetInputString(std::string s) { this->InputString = s; }
void SetInputString(const std::string& s) { this->InputString = s; }
//@}
/**
......
......@@ -34,7 +34,7 @@ public:
virtual void Execute();
void SetArgs(int argc, char *argv[], std::string fname)
void SetArgs(int argc, char *argv[], const std::string& fname)
{
this->Argc = argc;
this->Argv = argv;
......
......@@ -331,7 +331,7 @@ bool vtkXdmf3LightDataHandler::TooDeep(unsigned int depth)
}
//------------------------------------------------------------------------------
std::string vtkXdmf3LightDataHandler::UniqueName(std::string name, bool ForGrid)
std::string vtkXdmf3LightDataHandler::UniqueName(const std::string& name, bool ForGrid)
{
std::string gridName = name;
unsigned int count=1;
......
......@@ -504,7 +504,7 @@ int vtkContinuousScatterplot::RequestData(
// Effectively, we start processing a new cell at this point.
for (std::vector<vtkSmartPointer<vtkIdList> >::iterator faceIt = working->begin();
faceIt != working->end(); faceIt++)
faceIt != working->end(); ++faceIt)
{
fragmentFace = vtkSmartPointer<vtkIdList>::New();
residualFace = vtkSmartPointer<vtkIdList>::New();
......@@ -828,7 +828,7 @@ int vtkContinuousScatterplot::RequestData(
// for each face of the fragment
vtkSmartPointer<vtkIdList> poly = vtkSmartPointer<vtkIdList>::New();
for (std::vector<vtkSmartPointer<vtkIdList> >::iterator fc = outputQ[co]->begin();
fc != outputQ[co]->end(); fc++)
fc != outputQ[co]->end(); ++fc)
{
poly->Reset();
for (int pnr = 0; pnr < (*fc)->GetNumberOfIds(); pnr++)
......
......@@ -424,7 +424,7 @@ protected:
virtual void BuildAxis(vtkViewport *viewport);
static double ComputeStringOffset(double width, double height, double theta);
static void SetOffsetPosition(double xTick[3], double theta,
int stringHeight, int stringWidth,
int stringWidth, int stringHeight,
int offset, vtkActor2D *actor);
virtual void UpdateAdjustedRange();
......
......@@ -26,7 +26,7 @@ int PNGCompare(int argc, char *argv[])
std::string testImageFileName;
for (int i = 0; i < argc; ++i)
{
if ( strcmp(argv[i],"--test-file") == 0 && i < argc-1)
if (i < argc-1 && strcmp(argv[i],"--test-file") == 0)
{
testImageFileName = std::string(argv[i+1]);
break;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment