Commit 7e0b330b authored by Sean McBride's avatar Sean McBride Committed by Kitware Robot
Browse files

Merge topic 'more-cppcheck'

37893da8 Suppress cppcheck warnings with assert
3c16e52a Fixed potential null dereference warned by cppcheck
80e7073c Updated cppcheck suppressions for version 1.71
201984b9 Cleanup after evaluating cppcheck false positive
b23ee9f2 Fixed apparent mistake in error checking, where no errors actually caught
b6bb2bb3 Added an apparent omission of a counter increment
8ef03947 Removed useless comparison
ed7b14db

 Remove dead stores
...
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Reviewed-by: David Gobbi's avatarDavid Gobbi <david.gobbi@gmail.com>
Reviewed-by: Ben Boeckel's avatarBen Boeckel <ben.boeckel@kitware.com>
Merge-request: !934
parents 80ee339c 37893da8
......@@ -48,7 +48,7 @@ void vtkPistonScalarsColors::PrintSelf(ostream &os, vtkIndent indent)
//-----------------------------------------------------------------------------
void vtkPistonScalarsColors::SetTableRange(double range[2])
{
this->SetTableRange(range[1], range[2]);
this->SetTableRange(range[0], range[1]);
}
//-----------------------------------------------------------------------------
......
......@@ -13,11 +13,11 @@
//=========================================================================
// This file contains enough suppressions to result in no cppcheck warnings,
// at least on Mac OS X 10.9 with cppcheck 1.68.
// at least on Mac OS X 10.9 with cppcheck 1.71.
// To run:
// cd /path/to/VTK/
// cppcheck --platform=unix64 --enable=style -q --suppressions-list=CMake/VTKcppcheckSuppressions.txt --template='{file}:{line},{severity},{id},{message}' .
// cppcheck --platform=unix64 --enable=style -q --suppressions-list=CMake/VTKcppcheckSuppressions.txt --template='{id},{file}:{line},{severity},{message}' -j8 .
// Suppress everything from ThirdParty.
*:ThirdParty/*
......@@ -31,12 +31,16 @@ duplicateExpression:IO/PostgreSQL/vtkPostgreSQLQuery.cxx
obsoleteFunctionsasctime
unpreciseMathCall
// VTK assumes IEEE 754 floats, so this warning isn't useful.
memsetClassFloat
// There are just too many of these to manage, so suppress them all. Can look again one day.
clarifyCalculation
cstyleCast
invalidscanf
invalidscanf_libc
noCopyConstructor
noExplicitConstructor
operatorEqVarError
passedByValue
redundantAssignment
......@@ -52,29 +56,47 @@ argumentSize
// False positives.
argumentSize:Common/DataModel/vtkAMRBox.cxx
argumentSize:Common/DataModel/vtkStructuredGrid.h
arrayIndexOutOfBounds:Common/DataModel/vtkCell.h
assignBoolToPointer:Common/Math/vtkMatrix4x4.h
comparisonOfBoolWithInvalidComparator:Rendering/Label/vtkLabeledTreeMapDataMapper.cxx
deallocDealloc:Wrapping/Tools/vtkParseMerge.c
duplicateExpression:Common/Math/Testing/Cxx/TestPolynomialSolversUnivariate.cxx
duplicateExpression:Filters/General/vtkContourTriangulator.cxx
duplicateExpression:Filters/General/vtkVoxelContoursToSurfaceFilter.cxx
invalidPrintfArgType_int:Wrapping/PythonCore/vtkPythonUtil.cxx
knownConditionTrueFalse:Common/Core/Testing/Cxx/TestDataArrayIterators.cxx
memleak:Common/Core/Testing/Cxx/TestGarbageCollector.cxx
memleak:Examples/Infovis/Cxx/MultiView.cxx
memleak:Imaging/Hybrid/vtkSurfaceReconstructionFilter.cxx
multiCondition:Filters/Matlab/vtkMatlabMexAdapter.cxx
negativeIndex:Common/DataModel/vtkPerlinNoise.cxx
nullPointer:Interaction/Style/vtkInteractorStyleJoystickActor.cxx
nullPointer:Interaction/Style/vtkInteractorStyleTrackballActor.cxx
nullPointer:IO/Exodus/vtkExodusIIReaderParser.cxx
oppositeInnerCondition:Rendering/VolumeOpenGL/vtkOpenGLVolumeTextureMapper3D.cxx
pointerPositive:Common/DataModel/vtkUnstructuredGridCellIterator.cxx
redundantAssignInSwitch:Wrapping/Tools/vtkWrapPythonOverload.c
unassignedVariable:Common/Transforms/vtkHomogeneousTransform.cxx
unassignedVariable:Rendering/Core/vtkCamera.cxx
uninitdata:IO/Import/vtk3DSImporter.cxx
uninitvar:IO/Exodus/vtkExodusIIReader.cxx
unsafeClassCanLeak:Filters/General/vtkDensifyPolyData.cxx
unsafeClassCanLeak:Interaction/Widgets/vtkBiDimensionalRepresentation.h
unsafeClassCanLeak:Views/Qt/vtkQtListView.h:
unusedAllocatedMemory:IO/Legacy/vtkDataWriter.cxx
unusedStructMember:Common/Misc/vtkHeap.cxx
uselessAssignmentPtrArg:Filters/General/vtkYoungsMaterialInterface.cxx
uselessAssignmentPtrArg:IO/Parallel/vtkPImageWriter.cxx
uselessAssignmentPtrArg:Wrapping/Tools/vtkParse.tab.c
zerodiv:Filters/ParallelFlowPaths/Testing/Cxx/TestPStreamGeometry.cxx
// There are a fair number of these, but they are probably worth working through.
nullPointerRedundantCheck
duplInheritedMember
uninitvar
unusedStructMember
redundantCondition
stlIfStrFind
catchExceptionByValue
clarifyCondition
invalidPointerCast
......
......@@ -1923,7 +1923,6 @@ bool vtkGraph::ToDirectedGraph(vtkDirectedGraph* g)
}
else
{
g = NULL;
return false;
}
}
......@@ -1973,7 +1972,6 @@ bool vtkGraph::ToUndirectedGraph(vtkUndirectedGraph* g)
}
else
{
g = NULL;
return false;
}
}
......
......@@ -15,6 +15,7 @@
#include "vtkPerlinNoise.h"
#include "vtkObjectFactory.h"
#include <math.h>
#include <cassert>
vtkStandardNewMacro(vtkPerlinNoise);
......@@ -52,7 +53,7 @@ static void rand3abcd(int x, int y, int z, double outv[4])
}
static void interpolate(double f[4], int i, int n,
int xlim[3][2], double xarg[2])
int xlim[3][2], const double xarg[3])
{
double f0[4], f1[4];
......@@ -62,6 +63,7 @@ static void interpolate(double f[4], int i, int n,
return;
}
n--;
assert((n>=0)&&(n<=2));
interpolate(f0, i, n, xlim, xarg);
interpolate(f1, i | (1<<n), n, xlim, xarg);
......
......@@ -229,7 +229,7 @@ namespace
grid->GetCellData()->Initialize();
const char fieldName[] = "LinearField";
int offset = 1;
int numberOfComponents = 3;
const int numberOfComponents = 3;
CreateCellData(grid, numberOfComponents, offset, fieldName);
CreatePointData(grid, numberOfComponents, offset, fieldName);
......@@ -272,52 +272,49 @@ namespace
return EXIT_FAILURE;
}
if(numberOfComponents == 3)
// now check on the vorticity calculations
VTK_CREATE(vtkGradientFilter, cellVorticity);
cellVorticity->SetInputData(grid);
cellVorticity->SetInputScalars(
vtkDataObject::FIELD_ASSOCIATION_CELLS, fieldName);
cellVorticity->SetResultArrayName(resultName);
cellVorticity->SetComputeVorticity(1);
cellVorticity->Update();
VTK_CREATE(vtkGradientFilter, pointVorticity);
pointVorticity->SetInputData(grid);
pointVorticity->SetInputScalars(
vtkDataObject::FIELD_ASSOCIATION_POINTS, fieldName);
pointVorticity->SetResultArrayName(resultName);
pointVorticity->SetComputeVorticity(1);
pointVorticity->SetComputeQCriterion(1);
pointVorticity->Update();
// cell stuff
vtkDoubleArray* vorticityCellArray = vtkDoubleArray::SafeDownCast(
vtkDataSet::SafeDownCast(
cellVorticity->GetOutput())->GetCellData()->GetArray("Vorticity"));
if(!IsVorticityCorrect(gradCellArray, vorticityCellArray))
{
// now check on the vorticity calculations
VTK_CREATE(vtkGradientFilter, cellVorticity);
cellVorticity->SetInputData(grid);
cellVorticity->SetInputScalars(
vtkDataObject::FIELD_ASSOCIATION_CELLS, fieldName);
cellVorticity->SetResultArrayName(resultName);
cellVorticity->SetComputeVorticity(1);
cellVorticity->Update();
VTK_CREATE(vtkGradientFilter, pointVorticity);
pointVorticity->SetInputData(grid);
pointVorticity->SetInputScalars(
vtkDataObject::FIELD_ASSOCIATION_POINTS, fieldName);
pointVorticity->SetResultArrayName(resultName);
pointVorticity->SetComputeVorticity(1);
pointVorticity->SetComputeQCriterion(1);
pointVorticity->Update();
// cell stuff
vtkDoubleArray* vorticityCellArray = vtkDoubleArray::SafeDownCast(
vtkDataSet::SafeDownCast(
cellVorticity->GetOutput())->GetCellData()->GetArray("Vorticity"));
if(!IsVorticityCorrect(gradCellArray, vorticityCellArray))
{
return EXIT_FAILURE;
}
return EXIT_FAILURE;
}
// point stuff
vtkDoubleArray* vorticityPointArray = vtkDoubleArray::SafeDownCast(
vtkDataSet::SafeDownCast(
pointVorticity->GetOutput())->GetPointData()->GetArray("Vorticity"));
// point stuff
vtkDoubleArray* vorticityPointArray = vtkDoubleArray::SafeDownCast(
vtkDataSet::SafeDownCast(
pointVorticity->GetOutput())->GetPointData()->GetArray("Vorticity"));
if(!IsVorticityCorrect(gradPointArray, vorticityPointArray))
{
return EXIT_FAILURE;
}
vtkDoubleArray* qCriterionPointArray = vtkDoubleArray::SafeDownCast(
vtkDataSet::SafeDownCast(
pointVorticity->GetOutput())->GetPointData()->GetArray("Q-criterion"));
if(!IsQCriterionCorrect(gradPointArray, qCriterionPointArray))
{
return EXIT_FAILURE;
}
if(!IsVorticityCorrect(gradPointArray, vorticityPointArray))
{
return EXIT_FAILURE;
}
vtkDoubleArray* qCriterionPointArray = vtkDoubleArray::SafeDownCast(
vtkDataSet::SafeDownCast(
pointVorticity->GetOutput())->GetPointData()->GetArray("Q-criterion"));
if(!IsQCriterionCorrect(gradPointArray, qCriterionPointArray))
{
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
......
......@@ -299,7 +299,7 @@ void vtkCursor2D::SetFocalPoint(double x[3])
//---------------------------------------------------------------------------
void vtkCursor2D::SetModelBounds(const double bounds[6])
{
this->SetModelBounds(bounds[0], bounds[1], bounds[2], bounds[3], bounds[6], bounds[5]);
this->SetModelBounds(bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]);
}
//---------------------------------------------------------------------------
......
......@@ -112,6 +112,8 @@ void vtkWarpVectorExecute2(vtkWarpVector *self,
*outPts++ = *begin++ + scaleFactor * static_cast<OutputType>(*inVec++);
*outPts++ = *begin++ + scaleFactor * static_cast<OutputType>(*inVec++);
*outPts++ = *begin++ + scaleFactor * static_cast<OutputType>(*inVec++);
counter++;
}
}
......
......@@ -1265,7 +1265,7 @@ namespace
void Send(int msg, int rank, Task* task)
{
if(msg==TaskFinished)
if(task && (msg==TaskFinished))
{
PRINT("Done in "<<task->Point->GetNumSteps()<<" steps "<<task->NumHops<<" hops");
}
......
......@@ -302,6 +302,7 @@ void vtkBYUReader::ReadDisplacementFile(int numPts, vtkInformation *outInfo)
vtkErrorMacro(
<<"Error reading displacement file: " << this->DisplacementFileName
<< "Expected 3 floats, but got " << cnt);
fclose(dispFp);
return;
}
newVectors->SetTuple(i,v);
......@@ -349,6 +350,7 @@ void vtkBYUReader::ReadScalarFile(int numPts, vtkInformation *outInfo)
vtkErrorMacro(
<<"Error reading scalar file: " << this->ScalarFileName
<< "Expected 1 float, but got " << cnt);
fclose(scalarFp);
return;
}
......@@ -398,6 +400,7 @@ void vtkBYUReader::ReadTextureFile(int numPts, vtkInformation *outInfo)
vtkErrorMacro(
<<"Error reading texture file: " << this->TextureFileName
<< "Expected 2 texture coordibates, but got " << cnt);
fclose(textureFp);
return;
}
newTCoords->SetTuple(i,t);
......
......@@ -21,6 +21,8 @@
#include "vtkPointData.h"
#include "vtkMedicalImageProperties.h"
#include <cassert>
vtkStandardNewMacro(vtkGESignaReader);
......@@ -451,6 +453,8 @@ static void vtkcopygenesisimage(FILE *infp, int width, int height, int compress,
if (compress == 2 || compress == 4)
{ // packed/compacked
assert(map_left);
assert(map_wide);
start=map_left[row];
end=start+map_wide[row];
}
......
......@@ -578,7 +578,7 @@ void vtkVolume16Reader::AdjustSpacingAndOrigin (int dimensions[3], double spacin
}
//----------------------------------------------------------------------------
void vtkVolume16Reader::TransformSlice (unsigned short *slice, unsigned short *pixels, int k, int dimensions[3], int bounds[3])
void vtkVolume16Reader::TransformSlice (unsigned short *slice, unsigned short *pixels, int k, int dimensions[3], int bounds[6])
{
int iSize = this->DataDimensions[0];
int jSize = this->DataDimensions[1];
......
......@@ -2683,6 +2683,10 @@ int vtkDataReader::ReadCells(int size, int *data,
{
vtkErrorMacro(<<"Error reading binary cell data!" << " for file: "
<< (this->FileName?this->FileName:"(Null FileName)"));
if (tmp != data)
{
delete [] tmp;
}
return 0;
}
vtkByteSwap::Swap4BERange(tmp,size);
......
......@@ -97,7 +97,6 @@ int vtkPolyDataReader::RequestData(
int numPts=0;
char line[256];
int npts, size = 0, ncells, i;
int done=0;
vtkPolyData *output = vtkPolyData::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
int *tempArray;
......@@ -140,7 +139,7 @@ int vtkPolyDataReader::RequestData(
//
// Might find points, vertices, lines, polygons, or triangle strips
//
while (!done)
while (true)
{
if (!this->ReadString(line))
{
......
......@@ -151,7 +151,6 @@ int vtkRectilinearGridReader::RequestData(
int numPts=0, npts, ncoords, numCells=0, ncells;
char line[256];
int dimsRead=0;
int done=0;
vtkRectilinearGrid *output = vtkRectilinearGrid::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
......@@ -199,7 +198,7 @@ int vtkRectilinearGridReader::RequestData(
// Read keyword and number of points
//
while (!done)
while (true)
{
if (!this->ReadString(line))
{
......
......@@ -73,7 +73,6 @@ int vtkStructuredGridReader::RequestInformation(
int vtkStructuredGridReader::ReadMetaData(vtkInformation *outInfo)
{
char line[256];
int done=0;
if (!this->OpenVTKFile() || !this->ReadHeader())
{
......@@ -109,7 +108,7 @@ int vtkStructuredGridReader::ReadMetaData(vtkInformation *outInfo)
// Read keyword and dimensions
//
while (!done)
while (true)
{
if (!this->ReadString(line))
{
......@@ -164,7 +163,6 @@ int vtkStructuredGridReader::RequestData(
int numPts=0, npts=0, numCells=0, ncells;
char line[256];
int dimsRead=0;
int done=0;
vtkStructuredGrid *output = vtkStructuredGrid::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
......@@ -204,7 +202,7 @@ int vtkStructuredGridReader::RequestData(
// Read keyword and number of points
//
while (!done)
while (true)
{
if (!this->ReadString(line))
{
......
......@@ -77,7 +77,6 @@ int vtkStructuredPointsReader::ReadMetaData(vtkInformation *outInfo)
char line[256];
int dimsRead=0, arRead=0, originRead=0;
int done=0;
if (!this->OpenVTKFile() || !this->ReadHeader())
{
......@@ -113,7 +112,7 @@ int vtkStructuredPointsReader::ReadMetaData(vtkInformation *outInfo)
}
// Read keyword and number of points
while (!done)
while (true)
{
if (!this->ReadString(line))
{
......@@ -311,7 +310,6 @@ int vtkStructuredPointsReader::RequestData(
char line[256];
int npts, ncells;
int dimsRead=0, arRead=0, originRead=0;
int done=0;
vtkStructuredPoints *output = vtkStructuredPoints::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
......@@ -358,7 +356,7 @@ int vtkStructuredPointsReader::RequestData(
// Read keyword and number of points
//
numPts = output->GetNumberOfPoints(); // get default
while (!done)
while (true)
{
if (!this->ReadString(line))
{
......
......@@ -98,7 +98,6 @@ int vtkUnstructuredGridReader::RequestData(
int piece, numPieces, skip1, read2, skip3, tmp;
vtkCellArray *cells=NULL;
int *types=NULL;
int done=0;
vtkUnstructuredGrid *output = vtkUnstructuredGrid::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
int *tempArray;
......@@ -146,7 +145,7 @@ int vtkUnstructuredGridReader::RequestData(
// Might find points, cells, and cell types
//
while (!done)
while (true)
{
if (!this->ReadString(line))
{
......
......@@ -1727,6 +1727,7 @@ bool vtkMPASReader::ValidateDimensions(NcVar *var, bool silent, int ndims, ...)
<< dimName << "' at dimension index " << i << ", not '"
<< dim->name() << "'.");
}
va_end(args);
return false;
}
}
......
......@@ -254,7 +254,10 @@ void vtkEnSightWriter::WriteData()
this->TimeStep,fileBuffer);
FILE* ftemp=OpenFile(charBuffer);
if (!ftemp)
{
fclose(fd);
return;
}
pointArrayFiles.push_back(ftemp);
//write the description line to the file
......@@ -273,7 +276,10 @@ void vtkEnSightWriter::WriteData()
this->TimeStep,fileBuffer);
FILE* ftemp=OpenFile(charBuffer);
if (!ftemp)
{
fclose(fd);
return;
}
cellArrayFiles.push_back(ftemp);
//write the description line to the file
......
......@@ -1220,15 +1220,15 @@ void vtkXdmf3DataSet::VTKToXdmf(
bool OK = true;
vCoords = dataSet->GetXCoordinates();
OK |= vtkXdmf3DataSet::VTKToXdmfArray(vCoords, xZCoords.get());
OK &= vtkXdmf3DataSet::VTKToXdmfArray(vCoords, xZCoords.get());
if (OK)
{
vCoords = dataSet->GetYCoordinates();
OK |= vtkXdmf3DataSet::VTKToXdmfArray(vCoords, xYCoords.get());
OK &= vtkXdmf3DataSet::VTKToXdmfArray(vCoords, xYCoords.get());
if (OK)
{
vCoords = dataSet->GetZCoordinates();
OK |= vtkXdmf3DataSet::VTKToXdmfArray(vCoords, xXCoords.get());
OK &= vtkXdmf3DataSet::VTKToXdmfArray(vCoords, xXCoords.get());
}
}
......
......@@ -245,7 +245,6 @@ void vtkImageQuantizeRGBToIndexExecute(vtkImageQuantizeRGBToIndex *self,
vtkTimerLog *timer;
int totalCount;
double weight;
int done=0;
timer = vtkTimerLog::New();
timer->StartTimer();
......@@ -352,7 +351,7 @@ void vtkImageQuantizeRGBToIndexExecute(vtkImageQuantizeRGBToIndex *self,
rgbPtr++;
}
tmp = root;
while( !done )
while( true )
{
if ( tmp->GetIndex() != -1 )
{
......
......@@ -73,10 +73,10 @@ static void vtkDivideBy(double* a,double f)
}
// Routines for matrix creation
void vtkSRFreeMatrix(double **m, long nrl, long nrh, long ncl, long nch);
double **vtkSRMatrix(long nrl, long nrh, long ncl, long nch);
void vtkSRFreeVector(double *v, long nl, long nh);
double *vtkSRVector(long nl, long nh);
static void vtkSRFreeMatrix(double **m, long nrl, long nrh, long ncl, long nch);
static double **vtkSRMatrix(long nrl, long nrh, long ncl, long nch);
static void vtkSRFreeVector(double *v, long nl, long nh);
static double *vtkSRVector(long nl, long nh);
// set a matrix to zero
static void vtkSRMakeZero(double **m,long nrl, long nrh, long ncl, long nch)
......@@ -519,11 +519,10 @@ void vtkSRAddOuterProduct(double **m,double *v)
#define VTK_NR_END 1
// allocate a float vector with subscript range v[nl..nh]
double *vtkSRVector(long nl, long nh)
// must be balanced with vtkSRFreeVector.
static double *vtkSRVector(long nl, long nh)
{
double *v;
v = new double [nh-nl+1+VTK_NR_END];
double *v = new double [nh-nl+1+VTK_NR_END];
if (!v)
{
vtkGenericWarningMacro(<<"allocation failure in vector()");
......@@ -534,7 +533,8 @@ double *vtkSRVector(long nl, long nh)
}
// allocate a float matrix with subscript range m[nrl..nrh][ncl..nch]
double **vtkSRMatrix(long nrl, long nrh, long ncl, long nch)
// must be balanced with vtkSRFreeMatrix.
static double **vtkSRMatrix(long nrl, long nrh, long ncl, long nch)
{
long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
double **m;
......@@ -570,14 +570,14 @@ double **vtkSRMatrix(long nrl, long nrh, long ncl, long nch)
}
// free a double vector allocated with SRVector()
void vtkSRFreeVector(double *v, long nl, long vtkNotUsed(nh))
static void vtkSRFreeVector(double *v, long nl, long vtkNotUsed(nh))
{
delete [] (v+nl-VTK_NR_END);
}
// free a double matrix allocated by Matrix()
void vtkSRFreeMatrix(double **m, long nrl, long vtkNotUsed(nrh),
long ncl, long vtkNotUsed(nch))
static void vtkSRFreeMatrix(double **m, long nrl, long vtkNotUsed(nrh),
long ncl, long vtkNotUsed(nch))
{
delete [] (m[nrl]+ncl-VTK_NR_END);
......
......@@ -95,7 +95,7 @@ void vtkNetworkHierarchy::GetSubnets(unsigned int packedIP, int *subnets)
unsigned int vtkNetworkHierarchy::ITON(vtkStdString ip)
{
unsigned int subnets[4];
sscanf(ip.c_str(),"%d.%d.%d.%d",
sscanf(ip.c_str(),"%u.%u.%u.%u",
&(subnets[0]),&(subnets[1]),&(subnets[2]),&(subnets[3]));
int num = subnets[0];
num = num << 8;
......
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