Commit 442381f5 authored by Sean McBride's avatar Sean McBride

Fixed numerous warnings from the new cppcheck 1.81

Specifically:

very strange braces!
syntaxError,Common/DataModel/vtkHyperTreeGrid.cxx:699,error,syntax error

changed size()>0 to !empty()
stlSize,Filters/General/vtkLoopBooleanPolyDataFilter.cxx:1426,performance,Possible inefficient checking for 'nocellregion' emptiness.

This useless flag has been there since code was added in 2000 in f50b0909
knownConditionTrueFalse,Common/DataModel/vtkPointLocator.cxx:323,style,Condition 'flag' is always true
knownConditionTrueFalse,Common/DataModel/vtkPointLocator.cxx:415,style,Condition 'flag' is always true
knownConditionTrueFalse,Common/DataModel/vtkStaticPointLocator.cxx:788,style,Condition 'flag' is always true
knownConditionTrueFalse,Common/DataModel/vtkStaticPointLocator.cxx:879,style,Condition 'flag' is always true

This useless 'result' has been there since code was added in 2003 in dd39b9e4
knownConditionTrueFalse,IO/XML/vtkXMLRectilinearGridReader.cxx:236,style,Condition 'result' is always true
knownConditionTrueFalse,IO/XML/vtkXMLRectilinearGridReader.cxx:245,style,Condition 'result' is always true
knownConditionTrueFalse,IO/XML/vtkXMLRectilinearGridReader.cxx:254,style,Condition 'result' is always true

New check in cppcheck 1.81, block is indeed dead code:
oppositeInnerCondition,Rendering/OpenGL/vtkXOpenGLRenderWindow.cxx:272,warning,Opposite inner 'if' condition leads to a dead code block.
oppositeInnerCondition,Rendering/OpenGL/vtkXOpenGLRenderWindow.cxx:293,warning,Opposite inner 'if' condition leads to a dead code block.
oppositeInnerCondition,Rendering/OpenGL/vtkXOpenGLRenderWindow.cxx:349,warning,Opposite inner 'if' condition leads to a dead code block.

false positive, suppressed with zero initialization:
uninitvar,Filters/Statistics/vtkKMeansStatistics.cxx:810,error,Uninitialized variable: curDistance
uninitvar,Filters/Statistics/vtkKMeansStatistics.cxx:812,error,Uninitialized variable: curDistance

free(NULL) is allowed, so just remove null check
knownConditionTrueFalse,IO/Geometry/Testing/Cxx/TestIncrementalOctreePointLocator.cxx:920,style,Condition 'truthIds' is always false
knownConditionTrueFalse,IO/Geometry/Testing/Cxx/TestIncrementalOctreePointLocator.cxx:956,style,Condition 'diskFile' is always false

Simplified the calculation, verified same codegen on x86_64 with godbolt
shiftTooManyBitsSigned,Rendering/Volume/vtkHAVSVolumeMapper.cxx:53,error,Shifting signed 32-bit value by 31 bits is undefined behaviour

These have all been thus since their inception, but a global search find the same pattern in TestDijkstraGraphGeodesicPath.cxx, from which I copied the apparent solution
knownConditionTrueFalse,Interaction/Widgets/Testing/Cxx/TestPolygonalRepresentationHandleWidget.cxx:119,style,Condition 'distanceOffsetSpecified' is always false
knownConditionTrueFalse,Interaction/Widgets/Testing/Cxx/TestPolygonalRepresentationHandleWidget.cxx:199,style,Condition 'distanceOffsetSpecified' is always false
knownConditionTrueFalse,Interaction/Widgets/Testing/Cxx/TestPolygonalSurfaceConstrainedDistanceWidget.cxx:244,style,Condition 'distanceOffsetSpecified' is always false
knownConditionTrueFalse,Interaction/Widgets/Testing/Cxx/TestPolygonalSurfaceConstrainedDistanceWidget.cxx:325,style,Condition 'distanceOffsetSpecified' is always false
knownConditionTrueFalse,Interaction/Widgets/Testing/Cxx/TestSurfaceConstrainedHandleWidget.cxx:117,style,Condition 'distanceOffsetSpecified' is always false
knownConditionTrueFalse,Interaction/Widgets/Testing/Cxx/TestSurfaceConstrainedHandleWidget.cxx:189,style,Condition 'distanceOffsetSpecified' is always false

Toggle with #if instead
knownConditionTrueFalse,Imaging/Hybrid/vtkSurfaceReconstructionFilter.cxx:300,style,Condition 'orientationPropagation' is always true

Added parens
clarifyCalculation,Common/DataModel/vtkLagrangeWedge.cxx:906,style,Clarify calculation precedence for '/' and '?'.
parent 78373e17
......@@ -13,7 +13,7 @@
//=========================================================================
// This file contains enough suppressions to result in no cppcheck warnings,
// at least on macOS with cppcheck 1.80.
// at least on macOS with cppcheck 1.81.
// To run:
// cd /path/to/VTK/
......@@ -85,6 +85,8 @@ unusedStructMember:Common/Misc/vtkHeap.cxx
unusedStructMember:IO/Infovis/vtkTulipReader.cxx
uselessAssignmentArg:Common/DataModel/vtkReebGraph.cxx
uselessAssignmentPtrArg:Wrapping/Tools/vtkParse.tab.c
knownConditionTrueFalse:IO/Exodus/vtkExodusIIReader.cxx
knownConditionTrueFalse:IO/Geometry/Testing/Cxx/TestIncrementalOctreePointLocator.cxx
// false positive: <http://trac.cppcheck.net/ticket/7889>
knownConditionTrueFalse:IO/Parallel/vtkMultiBlockPLOT3DReader.cxx
......@@ -96,12 +98,16 @@ unassignedVariable:Rendering/Core/vtkCamera.cxx
// Not worth fixing, but not actually false positives.
duplicateExpression:Common/Math/Testing/Cxx/TestPolynomialSolversUnivariate.cxx
knownConditionTrueFalse:Common/Core/Testing/Cxx/UnitTestMath.cxx
knownConditionTrueFalse:GUISupport/Qt/QVTKWidget.cxx
knownConditionTrueFalse:Rendering/OpenGL/vtkXGPUInfoList.cxx
passedByValue:Filters/General/vtkYoungsMaterialInterface.cxx
knownConditionTrueFalse:IO/XML/Testing/Cxx/TestHyperOctreeIO.cxx
knownConditionTrueFalse:Rendering/OpenGL/vtkXGPUInfoList.cxx
knownConditionTrueFalse:Rendering/OpenGL2/vtkOpenGLRenderWindow.cxx
knownConditionTrueFalse:Rendering/OpenGL2/vtkOpenGLShaderCache.cxx
knownConditionTrueFalse:Filters/Parallel/Testing/Cxx/UnitTestPMaskPoints.cxx
knownConditionTrueFalse:Rendering/OSPRay/vtkOSPRayRendererNode.cxx
nullPointer:Wrapping/Tools/lex.yy.c
passedByValue:Filters/General/vtkYoungsMaterialInterface.cxx
// There are a fair number of these, but they are probably worth working through.
// 16 warnings
......
......@@ -696,6 +696,7 @@ public:
unsigned int n[3];
this->Grid->GetGridSize( n );
switch ( N )
{
case 2:
case 3:
{
......@@ -716,6 +717,7 @@ public:
this->Cursors[2]->Initialize( this->Grid, r );
}
return;
}
case 4:
case 9:
// dimension == 2
......
......@@ -304,7 +304,6 @@ vtkIdType vtkPointLocator::FindClosestPointWithinRadius(double radius,
return closest;
}
vtkDataArray *pointData = points->GetData();
int flag = 1;
//
// Find bucket point is in.
......@@ -320,14 +319,7 @@ vtkIdType vtkPointLocator::FindClosestPointWithinRadius(double radius,
for (j=0; j < nids; j++)
{
ptId = ptIds->GetId(j);
if (flag)
{
pointData->GetTuple(ptId, pt);
}
else
{
this->DataSet->GetPoint(ptId, pt);
}
pointData->GetTuple(ptId, pt);
if ( (dist2 = vtkMath::Distance2BetweenPoints(x,pt)) < minDist2 )
{
closest = ptId;
......@@ -412,14 +404,7 @@ vtkIdType vtkPointLocator::FindClosestPointWithinRadius(double radius,
for (j=0; j < nids; j++)
{
ptId = ptIds->GetId(j);
if (flag)
{
pointData->GetTuple(ptId, pt);
}
else
{
this->DataSet->GetPoint(ptId, pt);
}
pointData->GetTuple(ptId, pt);
if ( (dist2 = vtkMath::Distance2BetweenPoints(x,pt)) < minDist2 )
{
closest = ptId;
......
......@@ -769,7 +769,6 @@ FindClosestPointWithinRadius(double radius, const double x[3],
vtkDataArray *pointData =
static_cast<vtkPointSet *>(this->DataSet)->GetPoints()->GetData();
int flag = 1;
// Find the bucket the point is in.
//
......@@ -785,14 +784,7 @@ FindClosestPointWithinRadius(double radius, const double x[3],
for (j=0; j < numIds; j++)
{
ptId = ids[j].PtId;
if (flag)
{
pointData->GetTuple(ptId, pt);
}
else
{
this->DataSet->GetPoint(ptId, pt);
}
pointData->GetTuple(ptId, pt);
if ( (dist2 = vtkMath::Distance2BetweenPoints(x,pt)) < minDist2 )
{
closest = ptId;
......@@ -876,14 +868,7 @@ FindClosestPointWithinRadius(double radius, const double x[3],
for (j=0; j < numIds; j++)
{
ptId = ids[j].PtId;
if (flag)
{
pointData->GetTuple(ptId, pt);
}
else
{
this->DataSet->GetPoint(ptId, pt);
}
pointData->GetTuple(ptId, pt);
if ( (dist2 = vtkMath::Distance2BetweenPoints(x,pt)) < minDist2 )
{
closest = ptId;
......
......@@ -1423,7 +1423,7 @@ void vtkLoopBooleanPolyDataFilter::Impl::PerformBoolean(
nocellregion.push_back(i);
}
}
if (nocellregion.size() > 0)
if (!nocellregion.empty())
{
if (nocellregion.front() == 0)
{
......
......@@ -800,8 +800,8 @@ bool vtkKMeansAssessFunctor::Initialize( vtkTable* inData,
}
// Find the closest cluster center to the observation across all centers in the runID-th run.
vtkIdType j = runStartIdx;
double minDistance;
double curDistance;
double minDistance = 0.0;
double curDistance = 0.0;
(*dfunc)( minDistance, curClusterElements->GetRow( j ), dataElements->GetRow( observation ) );
vtkIdType localMemberID = 0;
for( /* no init */; j < runEndIdx; ++ j )
......
......@@ -900,7 +900,8 @@ int TestIncrementalOctreePointLocator( int argc, char * argv[] )
// memory clearance
dataPnts = nullptr; unstruct = nullptr;
dataPnts = nullptr;
unstruct = nullptr;
if ( ptIdList )
{
ptIdList->Delete();
......@@ -917,41 +918,26 @@ int TestIncrementalOctreePointLocator( int argc, char * argv[] )
ugReader = nullptr;
}
if ( truthIds )
{
free( truthIds );
truthIds = nullptr;
}
if ( resltIds )
{
free( resltIds );
resltIds = nullptr;
}
if ( pDataPts )
{
free( pDataPts );
pDataPts = nullptr;
}
if ( pLocPnts )
{
free( pLocPnts );
pLocPnts = nullptr;
}
if ( minDist2 )
{
free( minDist2 );
minDist2 = nullptr;
}
if ( maxDist2 )
{
free( maxDist2 );
maxDist2 = nullptr;
}
if ( clzNdst2 )
{
free( clzNdst2 );
clzNdst2 = nullptr;
}
free( truthIds );
truthIds = nullptr;
free( resltIds );
resltIds = nullptr;
free( pDataPts );
pDataPts = nullptr;
free( pLocPnts );
pLocPnts = nullptr;
free( minDist2 );
minDist2 = nullptr;
free( maxDist2 );
maxDist2 = nullptr;
free( clzNdst2 );
clzNdst2 = nullptr;
if ( diskFile )
{
......
......@@ -229,35 +229,26 @@ int vtkXMLRectilinearGridReader::ReadPieceData()
int* pieceExtent = this->PieceExtents + index*6;
vtkRectilinearGrid* output =
vtkRectilinearGrid::SafeDownCast(this->GetCurrentOutput());
int result = 1;
// Set the range of progress for the X coordinates array.
this->SetProgressRange(progressRange, 1, fractions);
if (result)
{
this->ReadSubCoordinates(pieceExtent, this->UpdateExtent,
this->SubExtent, xc,
output->GetXCoordinates());
}
this->ReadSubCoordinates(pieceExtent, this->UpdateExtent,
this->SubExtent, xc,
output->GetXCoordinates());
// Set the range of progress for the Y coordinates array.
this->SetProgressRange(progressRange, 2, fractions);
if (result)
{
this->ReadSubCoordinates(pieceExtent+2, this->UpdateExtent+2,
this->SubExtent+2, yc,
output->GetYCoordinates());
}
this->ReadSubCoordinates(pieceExtent+2, this->UpdateExtent+2,
this->SubExtent+2, yc,
output->GetYCoordinates());
// Set the range of progress for the Z coordinates array.
this->SetProgressRange(progressRange, 3, fractions);
if (result)
{
this->ReadSubCoordinates(pieceExtent+4, this->UpdateExtent+4,
this->SubExtent+4, zc,
output->GetZCoordinates());
}
return result;
this->ReadSubCoordinates(pieceExtent+4, this->UpdateExtent+4,
this->SubExtent+4, zc,
output->GetZCoordinates());
return 1;
}
//----------------------------------------------------------------------------
......
......@@ -296,9 +296,9 @@ int vtkSurfaceReconstructionFilter::RequestData(
// that has the lowest cost connection with a visited vertex. Record this
// vertex as visited, add any new neighbors to the neighbors list.
int orientationPropagation=1;
if(orientationPropagation)
{// set to false if you don't want orientation propagation (for testing)
// Disable if you don't want orientation propagation (for testing)
#if 1
{
vtkIdList *nearby = vtkIdList::New(); // list of nearby, unvisited points
// start with some vertex
......@@ -381,6 +381,7 @@ int vtkSurfaceReconstructionFilter::RequestData(
nearby->Delete();
}
#endif
//time(&t3);
......
......@@ -113,6 +113,7 @@ int TestPolygonalRepresentationHandleWidget(int argc, char*argv[])
if (strcmp("-DistanceOffset", argv[i]) == 0)
{
distanceOffset = atof(argv[i+1]);
distanceOffsetSpecified = true;
}
}
......
......@@ -238,6 +238,7 @@ int TestPolygonalSurfaceConstrainedDistanceWidget(int argc, char*argv[])
if (strcmp("-DistanceOffset", argv[i]) == 0)
{
distanceOffset = atof(argv[i+1]);
distanceOffsetSpecified = true;
}
}
......
......@@ -111,6 +111,7 @@ int TestSurfaceConstrainedHandleWidget(int argc, char*argv[])
if (strcmp("-DistanceOffset", argv[i]) == 0)
{
distanceOffset = atof(argv[i+1]);
distanceOffsetSpecified = true;
}
}
......
......@@ -269,10 +269,6 @@ vtkglX::GLXFBConfig *vtkXOpenGLRenderWindowGetDesiredFBConfig(
{
for (multi = win_multisamples; !fbc && multi >= 0; multi--)
{
if (fbc)
{
XFree(fbc);
}
fbc = vtkXOpenGLRenderWindowTryForFBConfig(DisplayId,
drawable_type,
win_doublebuffer,
......@@ -290,10 +286,6 @@ vtkglX::GLXFBConfig *vtkXOpenGLRenderWindowGetDesiredFBConfig(
{
for (multi = win_multisamples; !fbc && multi >= 0; multi--)
{
if (fbc)
{
XFree(fbc);
}
fbc = vtkXOpenGLRenderWindowTryForFBConfig(DisplayId,
drawable_type,
!win_doublebuffer,
......@@ -346,10 +338,6 @@ XVisualInfo *vtkXOpenGLRenderWindow::GetDesiredVisualInfo()
{
for (multi = this->MultiSamples; !v && multi >= 0; multi--)
{
if (v)
{
XFree(v);
}
v = vtkXOpenGLRenderWindowTryForVisual(this->DisplayId,
this->DoubleBuffer,
stereo, multi, alpha,
......
......@@ -50,7 +50,7 @@ public:
vtkHAVSSortedFace(unsigned int f, unsigned int d)
{
this->Face = f;
this->Distance = d ^ ((-(static_cast<int>(d) >> 31)) | 0x80000000);
this->Distance = d ^ ((d > 0x7FFFFFFF) ? 0x80000001 : 0x80000000);
}
bool operator<(const vtkHAVSSortedFace &rhs) const
......
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