From 17eb7c1bf3470274f91db2bf533f7f4c17717e16 Mon Sep 17 00:00:00 2001 From: Ken Martin <ken.martin@kitware.com> Date: Wed, 1 Nov 2017 11:41:58 -0400 Subject: [PATCH] rebased fix from MR 3232 Just a rebase of https://gitlab.kitware.com/vtk/vtk/merge_requests/3232 to fix a memory allocaiton issue. --- Filters/Core/vtkHull.cxx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Filters/Core/vtkHull.cxx b/Filters/Core/vtkHull.cxx index 8e0c0cdf9dc..88de1d9cbde 100644 --- a/Filters/Core/vtkHull.cxx +++ b/Filters/Core/vtkHull.cxx @@ -575,7 +575,7 @@ void vtkHull::ClipPolygonsFromPlanes( vtkPoints *outPoints, int i, j, k, q; double previousD, d, crosspoint; double *verts, *newVerts, *tmpVerts; - int vertCount, newVertCount; + int vertCount, newVertCount, oldSize; vtkIdType *pnts; // Use two arrays to store the vertices of the polygon @@ -583,7 +583,8 @@ void vtkHull::ClipPolygonsFromPlanes( vtkPoints *outPoints, newVerts = new double[3*(this->NumberOfPlanes+1)]; // We need an array to store the indices for the polygon - pnts = new vtkIdType[this->NumberOfPlanes-1]; + oldSize = this->NumberOfPlanes-1; + pnts = static_cast<vtkIdType*>(malloc(sizeof(vtkIdType) * oldSize)); // We have no vertices yet //vertCount = 0; @@ -671,6 +672,16 @@ void vtkHull::ClipPolygonsFromPlanes( vtkPoints *outPoints, if ( vertCount > 0 ) { + if ( vertCount > oldSize ) + { + vtkIdType *tmpPointer = static_cast<vtkIdType*>(realloc(pnts, vertCount * sizeof(vtkIdType))); + if (tmpPointer == nullptr) + { + vtkErrorMacro( << "Unable to allocate space for PointIds" ); + } + pnts = tmpPointer; + oldSize = vertCount; + } for ( j = 0; j < vertCount; j++ ) { pnts[j] = outPoints->InsertNextPoint( (verts + j*3) ); -- GitLab