Commit 6a56978e authored by Ben Boeckel's avatar Ben Boeckel Committed by Code Review

Merge topic 'cppcheck-20140919' into master

87935c2b TestIncrementalOctreePointLocator: remove dead code
898b425b vtkOpenGLPolyDataMapper2D: comment possible divide-by-zero
a59bd8c8 vtkReebGraph: add a comment about realloc usage
529dccb1 vtkParse: address cppcheck messages
ae3fa6e9 vtkParse: regenerate lex.yy.c
d6d6e8fc TestIncrementalOctreePointLocator: use malloc
79abddf1 vtkWrapHierarchy: handle realloc errors properly
86e47ae8 vtkParsePreprocess: fix up some free() logic for params
8aa578f3 vtkParsePreprocess: handle realloc errors properly
d28c44a6 vtkParseMain: close the input file
9aef0e71 vtkParseMain: handle realloc errors properly
f4e756f9 vtkResliceCursorRepresentation: avoid divide-by-zero
b0bd0465 vtkImagePlaneWidget: avoid divide-by-zero
e736ad42 vtkEnSightWriter: terminate buffers properly
b4b8206b vtkPLY: handle realloc errors properly
9a78aa1a vtkSLCReader: plug memory leak
...
parents 0ac359a1 87935c2b
......@@ -363,43 +363,49 @@ double vtkKdNode::_GetDistance2ToBoundary(
int first = 1;
minDistance = VTK_FLOAT_MAX; // Suppresses warning message.
dist = x - xmin;
if ((xmin != outerBoundaryMin[0]) &&
(((dist = x - xmin) < minDistance) || first))
((dist < minDistance) || first))
{
mindim = 0;
minDistance = dist;
first = 0;
}
dist = xmax - x;
if ((xmax != outerBoundaryMax[0]) &&
(((dist = xmax - x) < minDistance) || first))
((dist < minDistance) || first))
{
mindim = 1;
minDistance = dist;
first = 0;
}
dist = y - ymin;
if ((ymin != outerBoundaryMin[1]) &&
(((dist = y - ymin) < minDistance) || first))
((dist < minDistance) || first))
{
mindim = 2;
minDistance = dist;
first = 0;
}
dist = ymax - y;
if ((ymax != outerBoundaryMax[1]) &&
(((dist = ymax - y) < minDistance) || first))
((dist < minDistance) || first))
{
mindim = 3;
minDistance = dist;
first = 0;
}
dist = z - zmin;
if ((zmin != outerBoundaryMin[2]) &&
(((dist = z - zmin) < minDistance) || first))
((dist < minDistance) || first))
{
mindim = 4;
minDistance = dist;
first = 0;
}
dist = zmax - z;
if ((zmax != outerBoundaryMax[2]) &&
(((dist = zmax - z) < minDistance) || first))
((dist < minDistance) || first))
{
mindim = 5;
minDistance = dist;
......
......@@ -366,43 +366,49 @@ double vtkOctreePointLocatorNode::_GetDistance2ToBoundary(
int first = 1;
minDistance = VTK_FLOAT_MAX; // Suppresses warning message.
dist = x - xmin;
if ((xmin != outerBoundaryMin[0]) &&
(((dist = x - xmin) < minDistance) || first))
((dist < minDistance) || first))
{
mindim = 0;
minDistance = dist;
first = 0;
}
dist = xmax - x;
if ((xmax != outerBoundaryMax[0]) &&
(((dist = xmax - x) < minDistance) || first))
((dist < minDistance) || first))
{
mindim = 1;
minDistance = dist;
first = 0;
}
dist = y - ymin;
if ((ymin != outerBoundaryMin[1]) &&
(((dist = y - ymin) < minDistance) || first))
((dist < minDistance) || first))
{
mindim = 2;
minDistance = dist;
first = 0;
}
dist = ymax - y;
if ((ymax != outerBoundaryMax[1]) &&
(((dist = ymax - y) < minDistance) || first))
((dist < minDistance) || first))
{
mindim = 3;
minDistance = dist;
first = 0;
}
dist = z - zmin;
if ((zmin != outerBoundaryMin[2]) &&
(((dist = z - zmin) < minDistance) || first))
((dist < minDistance) || first))
{
mindim = 4;
minDistance = dist;
first = 0;
}
dist = zmax - z;
if ((zmax != outerBoundaryMax[2]) &&
(((dist = zmax - z) < minDistance) || first))
((dist < minDistance) || first))
{
mindim = 5;
minDistance = dist;
......
......@@ -2601,7 +2601,7 @@ int vtkPolyhedron::InternalContour(double value,
// incoming edge in the ceBackupMap.
std::vector<vtkIdVectorType> polygonVector;
vtkIdToIdVectorMapType::iterator ceMapIt, ceBackupMapIt;
vtkIdSetType::iterator cpSetIt;
vtkIdSetType::iterator cpSetIt = cpSet.end();
vtkIdVectorType::iterator cpVectorIt;
// backup ceMap. During graph travasal, we will remove edges from contour point
......
......@@ -117,7 +117,13 @@ if (a->ArcDwId1) this->GetArc(a->ArcDwId1)->ArcUpId1=a->ArcUpId1;\
if (nstack==mstack)\
{\
mstack=vtkReebGraphMax(128,mstack*2);\
int *oldstack = stack;\
stack=(int*)realloc(stack,sizeof(int)*mstack);\
if (!stack)\
{\
free(oldstack);\
assert(0 && "Ran out of memory");\
}\
} \
stack[nstack++]=(N);\
}
......
......@@ -124,8 +124,8 @@ void Cell::replaceNode (Node* oldNode, Node* newNode)
vector<Node*>::iterator it = std::find (_nodes.begin(), _nodes.end(), oldNode);
if (it != _nodes.end())
{
_nodes.erase (it);
_nodes.insert (it, newNode);
_nodes.erase (it);
oldNode->unregisterCell (this);
newNode->registerCell (this);
}
......
......@@ -42,9 +42,7 @@ int main( int, char *[] )
vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow( renWin);
planeSource->Update();
vtkPlaneSource* planeSource;
vtkPlaneSource* planeSource = vtkPlaneSource::New();
planeSource->Update();
vtkPolyDataMapper* planeSourceMapper = vtkPolyDataMapper::New();
......
......@@ -2660,6 +2660,11 @@ namespace vtkYoungsMaterialInterfaceCellCutInternals
REAL x = newtonSearchPolynomialFunc( surfaceFunction, derivatives[s], y, xmin, xmax );
DBG_MESG( "final x = "<< x );
FREE_LOCAL_ARRAY( derivatives, REAL2, nv-1 );
FREE_LOCAL_ARRAY( index, unsigned char, nv );
FREE_LOCAL_ARRAY( rindex, unsigned char, nv );
return x ;
}
......@@ -3025,6 +3030,11 @@ namespace vtkYoungsMaterialInterfaceCellCutInternals
REAL x = newtonSearchPolynomialFunc( volumeFunction, derivatives[s], y, xmin, xmax );
DBG_MESG( "final x = "<< x );
FREE_LOCAL_ARRAY( rindex, unsigned char, nv );
FREE_LOCAL_ARRAY( index, unsigned char, nv );
FREE_LOCAL_ARRAY( derivatives, REAL3, nv-1 );
return x ;
}
......
......@@ -1495,6 +1495,7 @@ int vtkUnstructuredGridGeometryFilter::RequestData(
// conn->Delete();
output->Squeeze();
delete [] cellVis;
return 1;
}
......
......@@ -2923,6 +2923,7 @@ int *vtkPKdTree::CollectLocalRegionProcessData()
if ( (regionId < 0) || (regionId >= numRegions))
{
VTKERROR("CollectLocalRegionProcessData - corrupt data");
delete [] cellCounts;
return NULL;
}
cellCounts[regionId]++;
......
......@@ -1586,6 +1586,7 @@ vtkFloatArray **
{
vtkErrorMacro(<<
"vtkDistributedDataFilter::ExchangeIdArrays memory allocation");
delete [] recvSize;
delete [] recvArrays;
return NULL;
}
......@@ -1707,6 +1708,8 @@ vtkIdTypeArray **
{
vtkErrorMacro(<<
"vtkDistributedDataFilter::ExchangeIdArrays memory allocation");
delete [] sendSize;
delete [] recvSize;
return NULL;
}
mpiContr->NoBlockReceive(recvArrays[source], recvSize[source], source, tag, req);
......
......@@ -723,14 +723,14 @@ void vtkKMeansStatistics::SelectAssessFunctor( vtkTable* inData,
return;
}
vtkKMeansAssessFunctor* kmfunc = vtkKMeansAssessFunctor::New();
if ( ! this->DistanceFunctor )
{
vtkErrorMacro( "Distance functor is NULL" );
return;
}
vtkKMeansAssessFunctor* kmfunc = vtkKMeansAssessFunctor::New();
if ( ! kmfunc->Initialize( inData, reqModel, this->DistanceFunctor ) )
{
delete kmfunc;
......
......@@ -172,7 +172,9 @@ public:
void SetFileName( char * fileName ) { this->FileName = fileName; }
const char* GetParticleName(char* variableName)
{
return( GetSeparatedParticleName(std::string(variableName)).c_str() );
static std::string particleName;
particleName = GetSeparatedParticleName(std::string(variableName));
return particleName.c_str();
}
void ReadMetaData();
......
......@@ -2125,7 +2125,7 @@ std::string vtkExodusIIWriter::CreateNameForScalarArray(
s = s.substr (0, MAX_STR_LENGTH - 11);
}
// assume largest for 32 bit decimal representation
char n[10];
char n[11];
sprintf (n, "%10d", component);
s.append (n);
return s;
......
......@@ -55,15 +55,6 @@
#define INC_OCT_PNT_LOC_TESTS_ZERO 0.00000000000001
// NOTE: ALL THE FOLLOWING FLAGS SHOULD BE OFF
//#ifdef _BRUTE_FORCE_VERIFICATION_
//#define _BRUTE_FORCE_VERIFICATION_WRITE_RESULT_
//#define _BRUTE_FORCE_VERIFICATION_WRITE_DISTANCE2_ // do NOT turn this ON
//#endif
// ---------------------------------------------------------------------------
// Meta information of the test data
//
......@@ -166,15 +157,11 @@ int TestIncrementalOctreePointLocator( int argc, char * argv[] )
// open a file for reading or writing the ground truth data
fileName = vtkTestUtilities::ExpandDataFileName
( argc, argv, "Data/IncOctPntLocResult.dat" );
#ifdef _BRUTE_FORCE_VERIFICATION_WRITE_RESULT_
diskFile = fopen( fileName, "wb" );
#else
#ifndef _BRUTE_FORCE_VERIFICATION_
diskFile = fopen( fileName, "rb" );
truthIds = ( vtkIdType * )
realloc( truthIds, sizeof( vtkIdType ) * numbPnts );
#endif
#endif
delete [] fileName; fileName = NULL;
......@@ -360,29 +347,6 @@ int TestIncrementalOctreePointLocator( int argc, char * argv[] )
#endif
// ---------------------------------------------------------------------
// write the point indices as the ground truth
#ifdef _BRUTE_FORCE_VERIFICATION_WRITE_RESULT_
if ( retValue == 0 )
{
numInsrt = ptIdList->GetNumberOfIds();
n = fwrite( &numInsrt, sizeof( int ), 1, diskFile );
if (n != 1)
{
cerr << "IO error " << __FILE__ << ":" << __LINE__ << "\n";
return 1;
}
n = fwrite( ptIdList->GetPointer( 0 ),
sizeof( vtkIdType ), numInsrt, diskFile );
if (n != static_cast<size_t>(numInsrt))
{
cerr << "IO error " << __FILE__ << ":" << __LINE__ << "\n";
return 1;
}
}
#endif
// -------------------------------------------------------------------//
} // end of two tolerances and three functions
......@@ -457,9 +421,9 @@ int TestIncrementalOctreePointLocator( int argc, char * argv[] )
SwapForBigEndian
( ( unsigned char * ) ( &nLocPnts ), sizeof( int ), 1 );
#endif
pLocPnts = ( double * ) realloc( pLocPnts, sizeof( double ) * nLocPnts * 3 );
minDist2 = ( double * ) realloc( minDist2, sizeof( double ) * nLocPnts );
maxDist2 = ( double * ) realloc( maxDist2, sizeof( double ) * nLocPnts );
pLocPnts = ( double * ) malloc( sizeof( double ) * nLocPnts * 3 );
minDist2 = ( double * ) malloc( sizeof( double ) * nLocPnts );
maxDist2 = ( double * ) malloc( sizeof( double ) * nLocPnts );
n = fread( pLocPnts, sizeof( double ), nLocPnts * 3, pntsFile );
if (n != static_cast<size_t>(nLocPnts * 3))
{
......@@ -567,28 +531,6 @@ int TestIncrementalOctreePointLocator( int argc, char * argv[] )
// ---------------------------------------------------------------------//
#endif
// -----------------------------------------------------------------------
// write the point indices as the ground truth
#ifdef _BRUTE_FORCE_VERIFICATION_WRITE_RESULT_
if ( retValue == 0 )
{
n = fwrite( &nLocPnts, sizeof( int ), 1, diskFile );
if (n != 1)
{
cerr << "IO error " << __FILE__ << ":" << __LINE__ << "\n";
return 1;
}
n = fwrite( resltIds, sizeof( vtkIdType ), nLocPnts, diskFile );
if (n != static_cast<size_t>(nLocPnts))
{
cerr << "IO error " << __FILE__ << ":" << __LINE__ << "\n";
return 1;
}
}
#endif
// ---------------------------------------------------------------------//
if ( retValue == 1 ) continue;
......@@ -654,10 +596,8 @@ int TestIncrementalOctreePointLocator( int argc, char * argv[] )
// write some data for locating the closest point
// within a radius and the points within a radius
//#ifdef _BRUTE_FORCE_VERIFICATION_WRITE_DISTANCE2_
minDist2[i] = clzNdst2[0];
maxDist2[i] = clzNdst2[ nClzNpts - 1 ];
//#endif
// check if there are any ignored but closer points
for ( j = 0; ( j < numbPnts ) && ( retValue == 0 ); j ++ )
......@@ -682,28 +622,6 @@ int TestIncrementalOctreePointLocator( int argc, char * argv[] )
// ---------------------------------------------------------------------//
// ---------------------------------------------------------------------//
// -----------------------------------------------------------------------
// write the point indices as the ground truth
#ifdef _BRUTE_FORCE_VERIFICATION_WRITE_RESULT_
if ( retValue == 0 )
{
numInsrt = nClzNpts * nLocPnts;
n = fwrite( &numInsrt, sizeof( int ), 1, diskFile );
if (n != 1)
{
cerr << "IO error " << __FILE__ << ":" << __LINE__ << "\n";
return 1;
}
n = fwrite( resltIds, sizeof( vtkIdType ), numInsrt, diskFile );
if (n != static_cast<size_t>(numInsrt))
{
cerr << "IO error " << __FILE__ << ":" << __LINE__ << "\n";
return 1;
}
}
#endif
// ---------------------------------------------------------------------//
// -----------------------------------------------------------------------
// rapid point index-based verification
#ifndef _BRUTE_FORCE_VERIFICATION_
......@@ -765,28 +683,6 @@ int TestIncrementalOctreePointLocator( int argc, char * argv[] )
#endif
}
// -----------------------------------------------------------------------
// write the point indices as the ground truth
#ifdef _BRUTE_FORCE_VERIFICATION_WRITE_RESULT_
if ( retValue == 0 )
{
numInsrt = nLocPnts * 3; // as we test three radii
n = fwrite( &numInsrt, sizeof( int ), 1, diskFile );
if (n != 1)
{
cerr << "IO error " << __FILE__ << ":" << __LINE__ << "\n";
return 1;
}
n = fwrite( resltIds, sizeof( vtkIdType ), numInsrt, diskFile );
if (n != static_cast<size_t>(numInsrt))
{
cerr << "IO error " << __FILE__ << ":" << __LINE__ << "\n";
return 1;
}
}
#endif
// ---------------------------------------------------------------------//
// -----------------------------------------------------------------------
// rapid point index-based verification
#ifndef _BRUTE_FORCE_VERIFICATION_
......@@ -951,29 +847,6 @@ int TestIncrementalOctreePointLocator( int argc, char * argv[] )
// -------------------------------------------------------------------//
}
// -----------------------------------------------------------------------
// write the point indices as the ground truth
#ifdef _BRUTE_FORCE_VERIFICATION_WRITE_RESULT_
if ( retValue == 0 )
{
numInsrt = ptIdList->GetNumberOfIds();
n = fwrite( &numInsrt, sizeof( int ), 1, diskFile );
if (n != 1)
{
cerr << "IO error " << __FILE__ << ":" << __LINE__ << "\n";
return 1;
}
n = fwrite( ptIdList->GetPointer( 0 ),
sizeof( vtkIdType ), numInsrt, diskFile );
if (n != static_cast<size_t>(numInsrt))
{
cerr << "IO error " << __FILE__ << ":" << __LINE__ << "\n";
return 1;
}
}
#endif
// ---------------------------------------------------------------------//
// -----------------------------------------------------------------------
// rapid point index-based verification
#ifndef _BRUTE_FORCE_VERIFICATION_
......@@ -1013,132 +886,6 @@ int TestIncrementalOctreePointLocator( int argc, char * argv[] )
}
// =========================================================================
// ================== DO NOT TURN ON THIS SEGMENT OF CODE ==================
// =========================================================================
#ifdef _BRUTE_FORCE_VERIFICATION_WRITE_DISTANCE2_
fileName = vtkTestUtilities::ExpandDataFileName
( argc, argv, "Data/IncOctPntLocData.dat" );
pntsFile = fopen( fileName, "wb" );
delete [] fileName; fileName = NULL;
n = fwrite(&nLocPnts, sizeof( int ), 1, pntsFile );
if (n != 1)
{
cerr << "IO error " << __FILE__ << ":" << __LINE__ << "\n";
return 1;
}
n = fwrite( pLocPnts, sizeof( double ), nLocPnts * 3, pntsFile );
if (n != static_cast<size_t>(nLocPnts) * 3)
{
cerr << "IO error " << __FILE__ << ":" << __LINE__ << "\n";
return 1;
}
n = fwrite( minDist2, sizeof( double ), nLocPnts, pntsFile );
if (n != static_cast<size_t>(nLocPnts))
{
cerr << "IO error " << __FILE__ << ":" << __LINE__ << "\n";
return 1;
}
n = fwrite( maxDist2, sizeof( double ), nLocPnts, pntsFile );
if (n != static_cast<size_t>(nLocPnts))
{
cerr << "IO error " << __FILE__ << ":" << __LINE__ << "\n";
return 1;
}
fclose( pntsFile ); pntsFile = NULL;
#endif
// =======================================================================//
// =======================================================================//
// =========================================================================
// ================== DO NOT TURN ON THIS SEGMENT OF CODE ==================
// =========================================================================
// NOTE: do *NOT* turn on this segment of code as the points resulting from
// the following random generator would change the points disk file!!!
// The points generated below are used to challenge point location.
// In case this segment is executed, it needs to be turned off and
// re-run the test with _BRUTE_FORCE_VERIFICATION_ on to create new
// disk files.
#if 0
int duplPnts = 200;
int inerPnts = 500;
int outrPnts = 300;
int totalPts = duplPnts + inerPnts + outrPnts;
int coordIdx = 0;
int gridIndx = 0;
double * ptCoords = ( double * ) malloc( sizeof( double ) * 3 * totalPts );
// duplicating grid points
for ( i = 0; i < duplPnts; i ++, coordIdx ++ )
{
gridIndx = rand() % numbPnts;
ptCoords[ ( coordIdx << 1 ) + coordIdx + 0 ] =
pDataPts[ ( gridIndx << 1 ) + gridIndx + 0 ];
ptCoords[ ( coordIdx << 1 ) + coordIdx + 1 ] =
pDataPts[ ( gridIndx << 1 ) + gridIndx + 1 ];
ptCoords[ ( coordIdx << 1 ) + coordIdx + 2 ] =
pDataPts[ ( gridIndx << 1 ) + gridIndx + 2 ];
}
// non-duplicate within-data points
// some randomly selected grid points are jittered, in each axis,
// between [ -0.1, 0.1 ] with resolution 0.001
for ( i = 0; i < inerPnts; i ++, coordIdx ++ )
{
gridIndx = ( rand() % numbPnts ) + ( numbPnts >> 1 );
gridIndx = gridIndx % numbPnts;
ptCoords[ ( coordIdx << 1 ) + coordIdx + 0 ] =
pDataPts[ ( gridIndx << 1 ) + gridIndx + 0 ] +
0.001 * ( ( ( rand() % 2 ) << 1 ) - 1 ) * ( rand() % 101 );
ptCoords[ ( coordIdx << 1 ) + coordIdx + 1 ] =
pDataPts[ ( gridIndx << 1 ) + gridIndx + 1 ] +
0.001 * ( ( ( rand() % 2 ) << 1 ) - 1 ) * ( rand() % 101 );
ptCoords[ ( coordIdx << 1 ) + coordIdx + 2 ] =
pDataPts[ ( gridIndx << 1 ) + gridIndx + 2 ] +
0.001 * ( ( ( rand() % 2 ) << 1 ) - 1 ) * ( rand() % 101 );
}
// outer points: x --- [ -5.0, -3.0 ] or [ 3.0, 5.0 ]
// AND
// y --- [ -5.0, -3.0 ] or [ 3.0, 5.0 ]
// AND
// z --- [ -5.0, -3.0 ] or [ 3.0, 5.0 ]
for ( i = 0; i < outrPnts; i ++, coordIdx ++ )
{
ptCoords[ ( coordIdx << 1 ) + coordIdx + 0 ] =
3.0 + 0.01 * ( rand() % 201 );
ptCoords[ ( coordIdx << 1 ) + coordIdx + 0 ] *=
( ( rand() % 2 ) << 1 ) - 1;
ptCoords[ ( coordIdx << 1 ) + coordIdx + 1 ] =
3.0 + 0.01 * ( rand() % 201 );
ptCoords[ ( coordIdx << 1 ) + coordIdx + 1 ] *=
( ( rand() % 2 ) << 1 ) - 1;
ptCoords[ ( coordIdx << 1 ) + coordIdx + 2 ] =
3.0 + 0.01 * ( rand() % 201 );
ptCoords[ ( coordIdx << 1 ) + coordIdx + 2 ] *=
( ( rand() % 2 ) << 1 ) - 1;
}
// write the points to a disk file
fileName = vtkTestUtilities::ExpandDataFileName
( argc, argv, "Data/IncOctPntLocData.dat" );
pntsFile = fopen( fileName, "wb" );
delete [] fileName; fileName = NULL;
fwrite( &totalPts, sizeof( int ), 1, pntsFile );
fwrite( ptCoords, sizeof( double ), totalPts * 3, pntsFile );
fclose( pntsFile ); pntsFile = NULL;