[vtkusers] Bug in vtkCharArray
Samson Timoner
samson at mit.edu
Mon Jul 7 14:46:25 EDT 2003
There is a Bug in vtkCharArray.cxx::DeepCopy(vtkDataArray *ia).
If the the command is sent a vtkDataArray that is not a vtkCharArray,
the command fails. The problem is that the following code is missing:
if ( ia->GetDataType() != VTK_CHAR )
{
vtkDataArray::DeepCopy(ia);
return;
}
Such code is found in vtkBitArray, vtkCharArray, vtkDoubleArray,
vtkFloatArray, vtkIdTypeArray, vtkIntArray, vtkLongArray, vtkShortArray,
vtkUnsignedCharArray, vtkUnsignedIntArray, vtkUnsignedLongArray,
and vtkUnsignedShortArray.
Looking through the CVS logs, it appears that the last time
all the data classes were re-written, someone simply forgot this
code in vtkCharArray.
-- Samson
P.S. Here is the current code and the fix for vtkCharArray.cxx
======================================================================
The Current Code is:
======================================================================
// Deep copy of another char array.
void vtkCharArray::DeepCopy(vtkDataArray *ia)
{
// Do nothing on a NULL input.
if (ia == NULL)
{
return;
}
if ( this != ia )
{
if ((this->Array) && (!this->SaveUserArray))
{
delete [] this->Array;
}
this->NumberOfComponents = ia->GetNumberOfComponents();
this->MaxId = ia->GetMaxId();
this->Size = ia->GetSize();
this->SaveUserArray = 0;
this->Array = new char[this->Size];
memcpy(this->Array, (char*) ia->GetVoidPointer(0), this->Size*sizeof(char));
}
}
======================================================================
The Fix is:
======================================================================
// Deep copy of another char array.
void vtkCharArray::DeepCopy(vtkDataArray *ia)
{
// Do nothing on a NULL input.
if (ia == NULL)
{
return;
}
if ( ia->GetDataType() != VTK_CHAR )
{
vtkDataArray::DeepCopy(ia);
return;
}
if ( this != ia )
{
if ((this->Array) && (!this->SaveUserArray))
{
delete [] this->Array;
}
this->NumberOfComponents = ia->GetNumberOfComponents();
this->MaxId = ia->GetMaxId();
this->Size = ia->GetSize();
this->SaveUserArray = 0;
this->Array = new char[this->Size];
memcpy(this->Array, (char*) ia->GetVoidPointer(0), this->Size*sizeof(char));
}
}
More information about the vtkusers
mailing list