Skip to content

Commit

Permalink
Compensate for recent changes to vtkDataArray
Browse files Browse the repository at this point in the history
-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()
  • Loading branch information
seanm committed Apr 26, 2016
1 parent 87f403d commit 9e0eb98
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions IO/MINC/vtkMINCImageAttributes.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -349,7 +356,6 @@ const char *vtkMINCImageAttributes::ConvertDataArrayToString(

// Store the string
std::string str = os.str();
const char *result = 0;

if (this->StringStore == 0)
{
Expand Down Expand Up @@ -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);
}

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9e0eb98

Please sign in to comment.