Commit b841a320 authored by Mathieu Malaterre's avatar Mathieu Malaterre

BUG: Fix seg fault when reading improper EnSight file (SNL issue). Will be backported to 2.0

parent 3f862f16
......@@ -28,7 +28,7 @@
#include <vtkstd/string>
#include <vtkstd/vector>
vtkCxxRevisionMacro(vtkEnSightReader, "1.55");
vtkCxxRevisionMacro(vtkEnSightReader, "1.56");
//----------------------------------------------------------------------------
typedef vtkstd::vector< vtkSmartPointer<vtkIdList> > vtkEnSightReaderCellIdsTypeBase;
......@@ -769,7 +769,33 @@ int vtkEnSightReader::ReadCaseFile()
}
else if (strncmp(line, "tensor", 6) == 0)
{
sscanf(line, " %*s %*s %*s %s", subLine);
// According to EnSight documentation tensor entry should be of the form:
// tensor symm per node/element
// but it seems like you can also find:
// tensor per node/element
// Let handle this case here:
char symm[10];
char per[10];
if( sscanf(line, " %*s %s %s %s", symm, per, subLine) != 3 )
{
vtkErrorMacro( "Error while reading: " << line );
}
if (!(strcmp(symm, "symm") == 0 && strcmp(per, "per") == 0))
{
if( sscanf(line, " %*s %s %s", per, subLine) != 2 )
{
vtkErrorMacro( "Error while reading: " << line );
}
if (strcmp(per, "per") == 0)
{
//Not valid file but seems alright, only 'symm' is missing
vtkWarningMacro( "Looks almost like a valid case file, continuing" );
}
else
{
vtkErrorMacro("Trouble reading: " << line );
}
}
if (strcmp(subLine, "node:") == 0)
{
vtkDebugMacro("tensor symm per node");
......@@ -826,6 +852,10 @@ int vtkEnSightReader::ReadCaseFile()
this->AddVariableType();
this->NumberOfTensorsSymmPerElement++;
}
else
{
vtkErrorMacro("Unknow type, faulty line was:" << line );
}
this->AddVariableFileName(subLine);
this->NumberOfVariables++;
}
......
......@@ -30,7 +30,7 @@
#include <assert.h>
#include <ctype.h> /* isspace */
vtkCxxRevisionMacro(vtkGenericEnSightReader, "1.70");
vtkCxxRevisionMacro(vtkGenericEnSightReader, "1.71");
vtkStandardNewMacro(vtkGenericEnSightReader);
vtkCxxSetObjectMacro(vtkGenericEnSightReader,TimeSets,
......@@ -593,6 +593,7 @@ void vtkGenericEnSightReader::SetCaseFileName(const char* fileName)
}
//----------------------------------------------------------------------------
// Internal function to read in a line up to 256 characters.
// Returns zero if there was an error.
int vtkGenericEnSightReader::ReadLine(char result[256])
......@@ -607,6 +608,7 @@ int vtkGenericEnSightReader::ReadLine(char result[256])
return 1;
}
//----------------------------------------------------------------------------
// Internal function to read in a line (from a binary file) up
// to 80 characters. Returns zero if there was an error.
int vtkGenericEnSightReader::ReadBinaryLine(char result[80])
......@@ -621,6 +623,7 @@ int vtkGenericEnSightReader::ReadBinaryLine(char result[80])
return 1;
}
//----------------------------------------------------------------------------
// Internal function that skips blank lines and comment lines
// and reads the next line it finds (up to 256 characters).
// Returns 0 is there was an error.
......
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