Commit 9e0eb985 authored by Sean McBride's avatar Sean McBride

Compensate for recent changes to vtkDataArray

-Changed ConvertDataArrayToString to return “” instead of null upon
empty vtkCharArray, matching previous behaviour before recent
vtkDataArray changes.  Public and private clients of this API expect
this behaviour.
-Defend against null from GetPointer()
parent 87f403db
......@@ -298,12 +298,19 @@ void vtkMINCImageAttributes::AddDimension(const char *dimension,
const char *vtkMINCImageAttributes::ConvertDataArrayToString(
vtkDataArray *array)
{
const char *result = 0;
int dataType = array->GetDataType();
if (dataType == VTK_CHAR)
{
vtkCharArray *charArray = vtkCharArray::SafeDownCast(array);
return charArray->GetPointer(0);
result = charArray->GetPointer(0);
if (!result)
{
result = "";
}
return result;
}
std::ostringstream os;
......@@ -349,7 +356,6 @@ const char *vtkMINCImageAttributes::ConvertDataArrayToString(
// Store the string
std::string str = os.str();
const char *result = 0;
if (this->StringStore == 0)
{
......@@ -698,7 +704,7 @@ const char *vtkMINCImageAttributes::GetAttributeValueAsString(
return 0;
}
// Convert any other array to a a string.
// Convert any other array to a string.
return this->ConvertDataArrayToString(array);
}
......@@ -719,12 +725,15 @@ int vtkMINCImageAttributes::GetAttributeValueAsInt(
if (array->GetDataType() == VTK_CHAR)
{
char *text = vtkCharArray::SafeDownCast(array)->GetPointer(0);
char *endp = text;
long result = strtol(text, &endp, 10);
// Check for complete conversion
if (*endp == '\0' && *text != '\0')
if (text)
{
return static_cast<int>(result);
char *endp = text;
long result = strtol(text, &endp, 10);
// Check for complete conversion
if (*endp == '\0' && *text != '\0')
{
return static_cast<int>(result);
}
}
}
else if (array->GetNumberOfTuples() == 1)
......@@ -768,12 +777,15 @@ double vtkMINCImageAttributes::GetAttributeValueAsDouble(
if (array->GetDataType() == VTK_CHAR)
{
char *text = vtkCharArray::SafeDownCast(array)->GetPointer(0);
char *endp = text;
double result = strtod(text, &endp);
// Check for complete conversion
if (*endp == '\0' && *text != '\0')
if (text)
{
return result;
char *endp = text;
double result = strtod(text, &endp);
// Check for complete conversion
if (*endp == '\0' && *text != '\0')
{
return result;
}
}
}
else if (array->GetNumberOfTuples() == 1)
......
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