Commit eb87b493 authored by Bill Lorensen's avatar Bill Lorensen

COMP: Fix recent coverity defects

Fixed recent coverity defects. Mostly checking bounds on scalars in
examples.
parent 84d62487
......@@ -49,7 +49,15 @@ int main(int, char*[])
graph->GetVertexData()->AddArray(labels);
vtkTree* tree = vtkTree::New();
tree->CheckedShallowCopy(graph);
bool validTree = tree->CheckedShallowCopy(graph);
if (!validTree)
{
std::cout << "Invalid tree" << std::endl;
graph->Delete();
labels->Delete();
tree->Delete();
return EXIT_FAILURE;
}
vtkGraphLayoutView* view = vtkGraphLayoutView::New();
view->SetRepresentationFromInput(tree);
......@@ -69,5 +77,5 @@ int main(int, char*[])
tree->Delete();
view->Delete();
return 0;
return EXIT_SUCCESS;;
}
......@@ -77,8 +77,15 @@ int main(int, char*[])
graph->GetVertexData()->AddArray(labels);
vtkTree* tree = vtkTree::New();
tree->CheckedShallowCopy(graph);
bool validTree = tree->CheckedShallowCopy(graph);
if (!validTree)
{
std::cout << "ERROR: Invalid tree" << std::endl;
graph->Delete();
labels->Delete();
tree->Delete();
return EXIT_FAILURE;
}
vtkGraphLayoutView* view = vtkGraphLayoutView::New();
vtkDataRepresentation* rep =
view->SetRepresentationFromInput(tree);
......@@ -118,6 +125,6 @@ int main(int, char*[])
link->Delete();
update->Delete();
return 0;
return EXIT_SUCCESS;
}
......@@ -57,7 +57,17 @@ int main (int argc, char *argv[])
// Define all of the variables
unsigned int startLabel = atoi(argv[2]);
if (startLabel > VTK_SHORT_MAX)
{
std::cout << "ERROR: startLabel is larger than " << VTK_SHORT_MAX << std::endl;
return EXIT_FAILURE;
}
unsigned int endLabel = atoi(argv[3]);
if (endLabel > VTK_SHORT_MAX)
{
std::cout << "ERROR: endLabel is larger than " << VTK_SHORT_MAX << std::endl;
return EXIT_FAILURE;
}
std::string filePrefix = "Cubes";
// Generate cubes from labels
......
......@@ -53,7 +53,17 @@ int main (int argc, char *argv[])
// Define all of the variables
unsigned int startLabel = atoi(argv[2]);
if (startLabel > VTK_SHORT_MAX)
{
std::cout << "ERROR: startLabel is larger than " << VTK_SHORT_MAX << std::endl;
return EXIT_FAILURE;
}
unsigned int endLabel = atoi(argv[3]);
if (endLabel > VTK_SHORT_MAX)
{
std::cout << "ERROR: endLabel is larger than " << VTK_SHORT_MAX << std::endl;
return EXIT_FAILURE;
}
std::string filePrefix = "Label";
unsigned int smoothingIterations = 15;
double passBand = 0.001;
......
......@@ -43,14 +43,15 @@ int main( int argc, char *argv[] )
if (argc < 2)
{
cout << "Usage: " << argv[0] << " financial_file" << endl;
return 1;
std::cout << "Usage: " << argv[0] << " financial_file" << endl;
return EXIT_FAILURE;
}
char* fname = argv[1];
// read data
vtkSmartPointer<vtkDataSet> dataSet = ReadFinancialData(fname, "MONTHLY_PAYMENT","INTEREST_RATE",
"LOAN_AMOUNT","TIME_LATE");
vtkSmartPointer<vtkDataSet> dataSet =
ReadFinancialData(fname, "MONTHLY_PAYMENT","INTEREST_RATE",
"LOAN_AMOUNT","TIME_LATE");
// construct pipeline for original population
vtkSmartPointer<vtkGaussianSplatter> popSplatter =
vtkSmartPointer<vtkGaussianSplatter>::New();
......@@ -145,7 +146,7 @@ int main( int argc, char *argv[] )
renWin->Render();
iren->Start();
return 0;
return EXIT_SUCCESS;
}
static vtkSmartPointer<vtkDataSet> ReadFinancialData(const char* filename, const char *x, const char *y, const char *z, const char *s)
......@@ -157,18 +158,29 @@ static vtkSmartPointer<vtkDataSet> ReadFinancialData(const char* filename, const
if ( (file = fopen(filename,"r")) == 0 )
{
cerr << "ERROR: Can't open file: " << filename << "\n";
std::cerr << "ERROR: Can't open file: " << filename << std::endl;
return NULL;
}
int n = fscanf (file, "%s %d", tag, &npts); // read number of points
if (n != 2)
{
cerr << "ERROR: Can't read file: " << filename << "\n";
std::cerr << "ERROR: Can't read file: " << filename << std::endl;
fclose(file);
return NULL;
}
// Check for a reasonable npts
if (npts <= 0)
{
std::cerr << "ERROR: Number of points must be greater that 0" << std::endl;
return NULL;
}
// We arbitrarily pick a large upper limit on npts
if (npts > VTK_INT_MAX / 10)
{
std::cerr << "ERROR: npts (" << npts << ") is unreasonably large" << std::endl;
return NULL;
}
vtkSmartPointer<vtkUnstructuredGrid> dataSet =
vtkSmartPointer<vtkUnstructuredGrid>::New();
float *xV = new float[npts];
......@@ -179,7 +191,7 @@ static vtkSmartPointer<vtkDataSet> ReadFinancialData(const char* filename, const
if ( ! ParseFile(file, x, xV) || ! ParseFile(file, y, yV) ||
! ParseFile(file, z, zV) || ! ParseFile(file, s, sV) )
{
cerr << "Couldn't read data!\n";
std::cerr << "ERROR: Couldn't read data!" << std::endl;
delete [] xV;
delete [] yV;
delete [] zV;
......@@ -226,7 +238,7 @@ static int ParseFile(FILE *file, const char *label, float *data)
if (fscanf(file, "%s %d", tag, &npts) != 2)
{
cerr << "IO Error " << __FILE__ << ":" << __LINE__ << "\n";
std::cerr << "ERROR: IO Error " << __FILE__ << ":" << __LINE__ << std::endl;
return 0;
}
......@@ -239,7 +251,7 @@ static int ParseFile(FILE *file, const char *label, float *data)
{
if (fscanf(file, "%f", data+i) != 1)
{
cerr << "IO Error " << __FILE__ << ":" << __LINE__ << "\n";
std::cerr << "ERROR: IO Error " << __FILE__ << ":" << __LINE__ << std::endl;
return 0;
}
if ( data[i] < min ) min = data[i];
......@@ -254,7 +266,7 @@ static int ParseFile(FILE *file, const char *label, float *data)
{
if (fscanf(file, "%*f") != 0)
{
cerr << "IO Error " << __FILE__ << ":" << __LINE__ << "\n";
std::cerr << "ERROR: IO Error " << __FILE__ << ":" << __LINE__ << std::endl;
return 0;
}
}
......
......@@ -35,7 +35,19 @@ int main (int argc, char *argv[])
double scalarRange[2];
reader->GetOutput()->GetPointData()->GetScalars()->GetRange(scalarRange);
// Check for a reasonable number of contours to avoid excessive
// computation. Here we arbitrarily pick an upper limit of 1000
int numberOfContours = atoi(argv[2]);
if (numberOfContours > 1000)
{
std::cout << "ERROR: the number of contours " << numberOfContours << " exceeds 1000" << std::endl;
return EXIT_FAILURE;
}
if (numberOfContours <= 0)
{
std::cout << "ERROR: the number of contours " << numberOfContours << " is <= 0" << std::endl;
return EXIT_FAILURE;
}
vtkSmartPointer<vtkBandedPolyDataContourFilter> bandedContours =
vtkSmartPointer<vtkBandedPolyDataContourFilter>::New();
......
......@@ -41,7 +41,19 @@ int main (int argc, char *argv[])
vtkSmartPointer<vtkAppendPolyData> appendFilledContours =
vtkSmartPointer<vtkAppendPolyData>::New();
// Check for a reasonable number of contours to avoid excessive
// computation. Here we arbitrarily pick an upper limit of 1000
int numberOfContours = atoi(argv[2]);
if (numberOfContours > 1000)
{
std::cout << "ERROR: the number of contours " << numberOfContours << " exceeds 1000" << std::endl;
return EXIT_FAILURE;
}
if (numberOfContours <= 0)
{
std::cout << "ERROR: the number of contours " << numberOfContours << " is <= 0" << std::endl;
return EXIT_FAILURE;
}
double delta =
(scalarRange[1] - scalarRange[0]) /
......
......@@ -223,7 +223,9 @@ RequestData(vtkInformation *vtkNotUsed(request),
else if (numPts == 0)
{
// Trivial case of no points - lets set it to 3
numValuesPerLine = 3;
vtkErrorMacro(<< "Could not process file " <<
this->FileName << " - No points specified");
return 0;
}
else
{
......
......@@ -630,7 +630,8 @@ void vtkMapper::ColorByArrayComponent(const char* arrayName, int component)
}
this->Modified();
strcpy(this->ArrayName, arrayName);
strncpy(this->ArrayName, arrayName, sizeof(this->ArrayName) - 1);
this->ArrayName[sizeof(this->ArrayName) - 1] = '\0';
this->ArrayComponent = component;
this->ArrayAccessMode = VTK_GET_ARRAY_BY_NAME;
}
......
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