vtkPolyData::GetCellPoints segfault when cell has not points (i.e. type is VTK_EMPTY_CELL)
Unlike the more efficient vtkPolyData::GetCellPoints(vtkIdType cellId, vtkIdType &npts, vtkIdType *pts)
function, the generic interface function which returns the list of cell points IDs as vtkIdList
causes a segfault when called with a cell that has type VTK_EMPTY_CELL
, e.g., after marking the cell as deleted. This is due to the following code which forces a pre-allocation of the list by inserting the point ID pts[npts-1]
first. But when npts == 0
, this causes an out of bounds memory access. Instead, an empty vtkIdList
should be returned. Why not use vtkIdList::SetNumberOfIds
instead of the ugly pre-insert ID?
//----------------------------------------------------------------------------
// Copy a cells point ids into list provided. (Less efficient.)
void vtkPolyData::GetCellPoints(vtkIdType cellId, vtkIdList *ptIds)
{
vtkIdType i;
vtkIdType *pts, npts;
ptIds->Reset();
if ( this->Cells == NULL )
{
this->BuildCells();
}
this->vtkPolyData::GetCellPoints(cellId, npts, pts);
ptIds->InsertId (npts-1,pts[npts-1]);
for (i=0; i<npts-1; i++)
{
ptIds->SetId(i,pts[i]);
}
}