From 9e0eb985c126c8090d2e5f3803e9f1c1605b485a Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Thu, 21 Apr 2016 17:13:50 -0400 Subject: [PATCH] Compensate for recent changes to vtkDataArray MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -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() --- IO/MINC/vtkMINCImageAttributes.cxx | 38 ++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/IO/MINC/vtkMINCImageAttributes.cxx b/IO/MINC/vtkMINCImageAttributes.cxx index 7a5615b781d..105cdaf8020 100644 --- a/IO/MINC/vtkMINCImageAttributes.cxx +++ b/IO/MINC/vtkMINCImageAttributes.cxx @@ -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(result); + char *endp = text; + long result = strtol(text, &endp, 10); + // Check for complete conversion + if (*endp == '\0' && *text != '\0') + { + return static_cast(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)