Skip to content

Commit

Permalink
Merge topic 'misc-fixes2' into master
Browse files Browse the repository at this point in the history
604952c Refactor old school alignment test to use offsetof()
82d3857 Removed simple dead stores/statements found by cppcheck
5da8067 Reverse order of AND statements
dd72b67 Refactor & simplify to avoid cppcheck false positive
13ee5b9 Add parens for less ambiguity, fix cppcheck warning
2f2c9e3 Copy-paste error, duplicate ORing
b85b5f6 Replace size() with empty()
c0f818b Fixed stack allocation to be properly aligned
da2c429 Removed unneeded casting
430ca63 Made various float to bool conversions explicit
00834ec Fixed cppcheck signConversion warning
ae942ec Fix incorrectStringCompare cppcheck warning
9557459 Fixed memory leaks found by cppcheck
bf7dbc5 Return upon error, otherwise invalid file reference is used
364f7a5 Add asserts to silence clang analyzer warning
af1c03d Fix clang warnings about implicit float->bool
...
  • Loading branch information
seanm authored and Code Review committed Feb 26, 2015
2 parents 82043c1 + 604952c commit 09fb8a2
Show file tree
Hide file tree
Showing 57 changed files with 143 additions and 146 deletions.
4 changes: 2 additions & 2 deletions Charts/Core/Testing/Cxx/TestAxes.cxx
Expand Up @@ -55,7 +55,7 @@ int TestAxes(int , char * [])
vtkAxis *axis = axesVertical[i].GetPointer();
axis->SetPoint1(vtkVector2f(i * 69 + 30, 10));
axis->SetPoint2(vtkVector2f(i * 69 + 30, 290));
axis->SetPosition(i % 2 ? vtkAxis::LEFT : vtkAxis::RIGHT);
axis->SetPosition((i % 2) ? vtkAxis::LEFT : vtkAxis::RIGHT);
axis->SetRange(NULL); // check that NULL pointers don't cause trouble
axis->SetRange(-1, 50);

Expand Down Expand Up @@ -93,7 +93,7 @@ int TestAxes(int , char * [])
vtkAxis *axis = axesHorizontal[i].GetPointer();
axis->SetPoint1(vtkVector2f(310, i * 50 + 30));
axis->SetPoint2(vtkVector2f(490, i * 50 + 30));
axis->SetPosition(i % 2 ? vtkAxis::TOP : vtkAxis::BOTTOM);
axis->SetPosition((i % 2) ? vtkAxis::TOP : vtkAxis::BOTTOM);
axis->SetRange(-1, 50);

view->GetScene()->AddItem(axis);
Expand Down
2 changes: 1 addition & 1 deletion Charts/Core/vtkPlotPoints.cxx
Expand Up @@ -882,7 +882,7 @@ void vtkPlotPoints::FindBadPoints()
}

// If there are bad points copy them, if not ensure the pointer is null.
if (bad.size() > 0)
if (!bad.empty())
{
if (!this->BadPoints)
{
Expand Down
6 changes: 6 additions & 0 deletions Common/Core/Testing/Cxx/UnitTestMath.cxx
Expand Up @@ -2108,6 +2108,12 @@ int InvertMatrix()
}
if (vtkMath::InvertMatrix(mat, matI, NDimension, tmp1, tmp2) == 0)
{
delete [] mat;
delete [] orig;
delete [] matI;
delete [] ident;
delete [] tmp1;
delete [] tmp2;
return status;
}
vtkMath::MultiplyMatrix(orig,
Expand Down
2 changes: 1 addition & 1 deletion Common/Core/vtkMath.cxx
Expand Up @@ -565,7 +565,7 @@ void vtkMath::LUSolveLinearSystem(double **A, int *index,
sum -= A[i][j]*x[j];
}
}
else if (sum)
else if (sum != 0.0)
{
ii = i;
}
Expand Down
2 changes: 1 addition & 1 deletion Common/DataModel/Testing/Cxx/TestCompositeDataSets.cxx
Expand Up @@ -52,7 +52,7 @@ bool TestDataObjectTreeIterator()
{
vtkNew<vtkUniformGrid> child;
blocks[parent]->SetBlock(
block, block % 2 ? NULL : child.GetPointer());
block, (block % 2) ? NULL : child.GetPointer());
blocks[parent]->GetMetaData(block)->Set(
vtkCompositeDataSet::NAME(), blockName.c_str());
++numLeaves;
Expand Down
2 changes: 1 addition & 1 deletion Common/DataModel/vtkAnimationScene.cxx
Expand Up @@ -160,7 +160,7 @@ void vtkAnimationScene::Play()

this->InPlay = 1;
this->StopPlay = 0;
this->FrameRate = (!this->FrameRate)? 1.0 : this->FrameRate;
this->FrameRate = (this->FrameRate == 0.0) ? 1.0 : this->FrameRate;
// the actual play loop, check for StopPlay flag.

double currenttime = this->AnimationTime;
Expand Down
2 changes: 1 addition & 1 deletion Common/DataModel/vtkBox.cxx
Expand Up @@ -171,7 +171,7 @@ double vtkBox::EvaluateFunction(double x[3])
else
{
dist = fabs(x[i]-minP[i]);
if (dist)
if ( dist > 0.0 )
{
inside = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion Common/DataModel/vtkHexagonalPrism.cxx
Expand Up @@ -379,7 +379,7 @@ int vtkHexagonalPrism::CellBoundary(int subId, double pcoords[3],

double dot = vtkMath::Dot2D(v, u);
double uNorm = vtkMath::Norm2D( u );
if (uNorm)
if (uNorm != 0.0)
{
dot /= uNorm;
}
Expand Down
2 changes: 1 addition & 1 deletion Common/DataModel/vtkHyperOctree.cxx
Expand Up @@ -344,8 +344,8 @@ template<unsigned int D> class vtkCompactHyperOctreeCursor
virtual vtkHyperOctreeCursor *Clone()
{
vtkCompactHyperOctreeCursor<D> *result=this->NewInstance();
result->Tree=this->Tree;
assert("post: results_exists" && result!=0);
result->Tree=this->Tree;
assert("post: same_tree" && result->SameTree(this));
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion Common/DataModel/vtkHyperTree.cxx
Expand Up @@ -229,8 +229,8 @@ template<int N> class vtkCompactHyperTreeCursor : public vtkHyperTreeCursor
virtual vtkHyperTreeCursor* Clone()
{
vtkCompactHyperTreeCursor<N>* result = this->NewInstance();
result->Tree = this->Tree;
assert( "post: results_exists" && result != 0 );
result->Tree = this->Tree;
assert( "post: same_tree" && result->SameTree( this ) );
return result;
}
Expand Down
4 changes: 2 additions & 2 deletions Common/DataModel/vtkHyperTreeGrid.cxx
Expand Up @@ -1415,7 +1415,7 @@ void vtkHyperTreeGrid::TraverseDualMaskedLeaf(
vtkHyperTreeSimpleCursor* cursor0 = superCursor->GetCursor( 0 );

// Check across D-face neighbors whether point must be adjusted
unsigned int f = 1;
int f = 1;
for ( unsigned int d = 0; d < this->Dimension; ++ d, f *= 3 )
{
// For each direction, check both orientations
Expand Down Expand Up @@ -1573,7 +1573,7 @@ void vtkHyperTreeGrid::TraverseDualLeaf( vtkHyperTreeGridSuperCursor* superCurso
// (D-2)-faces are corners, neighbors are +/- 5, 7, 11, 13

// Check across D-face neighbors whether point must be adjusted
unsigned int f = 1;
int f = 1;
for ( unsigned int d = 0; d < this->Dimension; ++ d, f *= 3 )
{
// Start at center
Expand Down
2 changes: 1 addition & 1 deletion Common/DataModel/vtkPointLocator.cxx
Expand Up @@ -320,7 +320,7 @@ vtkIdType vtkPointLocator::FindClosestPointWithinRadius(double radius,
refinedRadius2 = radius2;
}

if (inputDataLength)
if (inputDataLength != 0.0)
{
distance2ToDataBounds = this->Distance2ToBounds(x, this->Bounds);
maxDistance = sqrt(distance2ToDataBounds) + inputDataLength;
Expand Down
1 change: 0 additions & 1 deletion Common/DataModel/vtkPolyhedron.cxx
Expand Up @@ -2602,7 +2602,6 @@ int vtkPolyhedron::InternalContour(double value,
std::vector<vtkIdVectorType> polygonVector;
vtkIdToIdVectorMapType::iterator ceMapIt, ceBackupMapIt;
vtkIdSetType::iterator cpSetIt = cpSet.end();
vtkIdVectorType::iterator cpVectorIt;

// backup ceMap. During graph travasal, we will remove edges from contour point
// which can mess up the ordering.
Expand Down
2 changes: 1 addition & 1 deletion Common/DataModel/vtkQuadraticPolygon.cxx
Expand Up @@ -323,7 +323,7 @@ void vtkQuadraticPolygon::GetPermutationFromPolygon(vtkIdType nb,
permutation->SetNumberOfIds(nb);
for (vtkIdType i = 0; i < nb; i++)
{
permutation->SetId(i, (i % 2 ? (i + nb)/2 : i/2));
permutation->SetId(i, ((i % 2) ? (i + nb)/2 : i/2));
}
}

Expand Down
6 changes: 3 additions & 3 deletions Common/DataModel/vtkReebGraph.cxx
Expand Up @@ -1060,15 +1060,15 @@ vtkReebGraph::Implementation::vtkReebPath vtkReebGraph::Implementation::FindPath
if (M==N1)
{
//clear all the items in the priority queue
while (pq.size())
while (!pq.empty())
{
vtkReebPath aux=pq.top();pq.pop();
delete aux.ArcTable;
delete aux.NodeTable;
}

if (Ntouch) free(Ntouch);
if (Atouch) free(Atouch);
free(Ntouch);
free(Atouch);

vtkIdType* tmp=new vtkIdType[entry.NodeNumber+1];
memcpy(tmp,entry.NodeTable,sizeof(vtkIdType)*entry.NodeNumber);
Expand Down
12 changes: 6 additions & 6 deletions Common/Math/vtkPolynomialSolversUnivariate.cxx
Expand Up @@ -1569,7 +1569,7 @@ int vtkPolynomialSolversUnivariate::LinBairstowSolve( double* c, int d, double*
if ( delta >= 0 )
{
// check whether there are 2 simple roots or 1 double root
if ( delta )
if ( delta != 0.0 )
{
delta = sqrt( delta );
// we have 2 simple real roots
Expand Down Expand Up @@ -2141,28 +2141,28 @@ int vtkPolynomialSolversUnivariate::SolveQuadratic( double c1, double c2, double
// Returns either the number of roots, or -1 if ininite number of roots.
int vtkPolynomialSolversUnivariate::SolveQuadratic( double* c, double* r, int* m )
{
if( ! c[0] )
if( c[0] == 0.0 )
{
if( c[1] )
if( c[1] != 0.0 )
{
r[0] = -c[2] / c[1];
m[0] = 1;
return 1;
}
else
{
if ( c[2] ) return 0;
if ( c[2] != 0.0 ) return 0;
else return -1;
}
}

double delta = c[1] * c[1] - 4. * c[0] * c[2];

if ( delta >= 0. )
if ( delta >= 0.0 )
{
double fac = 1. / ( 2. * c[0] );
// check whether there are 2 simple or 1 double root(s)
if ( delta )
if ( delta != 0.0 )
{
delta = sqrt( delta );
// insert 1st simple real root
Expand Down
2 changes: 1 addition & 1 deletion Common/Misc/vtkFunctionParser.cxx
Expand Up @@ -1442,7 +1442,7 @@ void vtkFunctionParser::BuildInternalSubstringStructure(int beginIndex,
if (mathFunctionNum > 0)
{
beginIndex2 = beginIndex;
while (this->Function[beginIndex2] != '(' && beginIndex2 <= endIndex)
while (beginIndex2 <= endIndex && this->Function[beginIndex2] != '(')
{
beginIndex2++;
}
Expand Down
20 changes: 7 additions & 13 deletions Common/Misc/vtkHeap.cxx
Expand Up @@ -15,25 +15,19 @@
#include "vtkCommonMiscModule.h" // For export macro
#include "vtkHeap.h"
#include "vtkObjectFactory.h"
#include <cstddef>

vtkStandardNewMacro(vtkHeap);

struct vtkTestAlignLong
{
char pad;
long x;
};

static int vtkGetLongAlignment()
{
struct vtkTestAlignLong s1;
char * p1;
char * p2;

p1 = reinterpret_cast<char *>(&s1); // Get address of struct
p2 = reinterpret_cast<char *>(&s1.x); // Get address of long within struct
struct vtkTestAlignLong
{
char pad;
long x;
};

return (p2 - p1); // Get member offset/alignment
return offsetof(vtkTestAlignLong, x);
}

class VTKCOMMONMISC_EXPORT vtkHeapBlock
Expand Down
2 changes: 1 addition & 1 deletion Common/Transforms/vtkTransform.cxx
Expand Up @@ -474,7 +474,7 @@ void vtkTransform::GetOrientationWXYZ(double wxyz[4])
// calc the return value wxyz
double mag = sqrt( wxyz[1] * wxyz[1] + wxyz[2] * wxyz[2] + wxyz[3] * wxyz[3] );

if ( mag )
if ( mag != 0.0 )
{
wxyz[0] = 2. * vtkMath::DegreesFromRadians( acos( wxyz[0] ) );
wxyz[1] /= mag;
Expand Down
4 changes: 2 additions & 2 deletions Filters/Core/vtkDelaunay2D.cxx
Expand Up @@ -704,8 +704,8 @@ int vtkDelaunay2D::RequestData(
//traverse all points, create vertices if none used
for (ptId=0; ptId<(numPoints+8); ptId++)
{
if ( !pointUse[ptId]
&& (ptId < numPoints || this->BoundingTriangulation) )
if ( (ptId < numPoints || this->BoundingTriangulation)
&& !pointUse[ptId] )
{
pts[0] = ptId;
alphaVerts->InsertNextCell(1,pts);
Expand Down
2 changes: 1 addition & 1 deletion Filters/Core/vtkDelaunay3D.cxx
Expand Up @@ -700,7 +700,7 @@ int vtkDelaunay3D::RequestData(
//traverse all points, create vertices if none used
for (ptId=0; ptId<(numPoints+6); ptId++)
{
if (!pointUse[ptId] && (ptId < numPoints || this->BoundingTriangulation))
if ((ptId < numPoints || this->BoundingTriangulation) && !pointUse[ptId])
{
pts[0] = ptId;
output->InsertNextCell(VTK_VERTEX,1,pts);
Expand Down
2 changes: 1 addition & 1 deletion Filters/General/vtkImageMarchingCubes.cxx
Expand Up @@ -595,7 +595,7 @@ void vtkImageMarchingCubesMarch(vtkImageMarchingCubes *self,
unsigned long target, count;

// avoid warnings
ptr = ptr;
(void)ptr;

// Get information to loop through images.
inData->GetExtent(min0, max0, min1, max1, min2, max2);
Expand Down
2 changes: 1 addition & 1 deletion Filters/General/vtkMultiThreshold.cxx
Expand Up @@ -716,7 +716,7 @@ void vtkMultiThreshold::UpdateDependents(
}
}
}
decision = cnt % 2 ? INCLUDE : EXCLUDE;
decision = (cnt % 2) ? INCLUDE : EXCLUDE;
}
break;
case NAND:
Expand Down
4 changes: 2 additions & 2 deletions Filters/Geometry/vtkStructuredAMRGridConnectivity.cxx
Expand Up @@ -2097,7 +2097,7 @@ void vtkStructuredAMRGridConnectivity::GetCoarsenedExtent(
void vtkStructuredAMRGridConnectivity::CoarsenExtent(
int orient[3], int ndim, int fromLevel, int toLevel, int ext[6])
{
assert("pre: ndim must be either 1, 2 or 3" && (ndim > 0 || ndim <= 3) );
assert("pre: ndim must be either 1, 2 or 3" && (ndim > 0 && ndim <= 3) );

if( this->HasConstantRefinementRatio() )
{
Expand Down Expand Up @@ -2161,7 +2161,7 @@ void vtkStructuredAMRGridConnectivity::GetRefinedExtent(
void vtkStructuredAMRGridConnectivity::RefineExtent(
int orient[3], int ndim, int fromLevel, int toLevel, int ext[6])
{
assert("pre: ndim must be either 1, 2 or 3" && (ndim > 0 || ndim <= 3) );
assert("pre: ndim must be either 1, 2 or 3" && (ndim > 0 && ndim <= 3) );

if( this->HasConstantRefinementRatio() )
{
Expand Down
2 changes: 1 addition & 1 deletion Filters/Hybrid/vtkTransformToGrid.cxx
Expand Up @@ -370,7 +370,7 @@ void vtkTransformToGrid::RequestData(
grid->AllocateScalars(outInfo);
int *extent = grid->GetExtent();

double *gridPtr = (double *)grid->GetScalarPointerForExtent(extent);
void *gridPtr = grid->GetScalarPointerForExtent(extent);
int gridType = grid->GetScalarType();

this->UpdateShiftScale();
Expand Down
10 changes: 10 additions & 0 deletions Filters/Hybrid/vtkWeightedTransformFilter.cxx
Expand Up @@ -318,6 +318,8 @@ int vtkWeightedTransformFilter::RequestData(
{
vtkErrorMacro(<<"WeightArray " << this->WeightArray <<
" " << "doesn't exist");
delete [] linearNormMtx;
delete [] linearPtMtx;
return 1;
}

Expand Down Expand Up @@ -348,6 +350,8 @@ int vtkWeightedTransformFilter::RequestData(
{
vtkErrorMacro(<<"TransformIndexArray " << this->TransformIndexArray <<
" " << "doesn't exist");
delete [] linearNormMtx;
delete [] linearPtMtx;
return 1;
}

Expand Down Expand Up @@ -387,6 +391,8 @@ int vtkWeightedTransformFilter::RequestData(
{
vtkErrorMacro(<<"CellDataWeightArray " << this->CellDataWeightArray <<
" " << "doesn't exist");
delete [] linearNormMtx;
delete [] linearPtMtx;
return 1;
}
cdComponents = cdArray->GetNumberOfComponents();
Expand Down Expand Up @@ -420,6 +426,8 @@ int vtkWeightedTransformFilter::RequestData(
vtkErrorMacro(<<"CellDataTransformIndexArray " <<
this->CellDataTransformIndexArray <<
" " << "doesn't exist");
delete [] linearNormMtx;
delete [] linearPtMtx;
return 1;
}

Expand Down Expand Up @@ -450,6 +458,8 @@ int vtkWeightedTransformFilter::RequestData(
if ( !inPts )
{
vtkErrorMacro(<<"No input data");
delete [] linearNormMtx;
delete [] linearPtMtx;
return 1;
}

Expand Down
2 changes: 2 additions & 0 deletions Filters/ParallelMPI/vtkDistributedDataFilter.cxx
Expand Up @@ -1710,6 +1710,7 @@ vtkIdTypeArray **
"vtkDistributedDataFilter::ExchangeIdArrays memory allocation");
delete [] sendSize;
delete [] recvSize;
delete [] recvArrays;
return NULL;
}
mpiContr->NoBlockReceive(recvArrays[source], recvSize[source], source, tag, req);
Expand Down Expand Up @@ -1859,6 +1860,7 @@ vtkUnstructuredGrid *
{
vtkErrorMacro(<<
"vtkDistributedDataFilter::ExchangeMergeSubGrids memory allocation");
delete [] grids;
return NULL;
}
recvBufSize = packedGridRecvSize;
Expand Down

0 comments on commit 09fb8a2

Please sign in to comment.