Commit 3978a87e authored by Berk Geveci's avatar Berk Geveci

Fixed issue in filter leading to sanitizer errors.

vtkDataSetSurfaceFilter had some funky code designed to optimize
(minimize) allocation of small objects. This required apparently
writing beyond the limits of an array. It was not a bug but made
tools like the clang sanitizer think that it was. Fixed it while
still maintaining the allocation optimization, at the cost of a
bit more memory usage.

Change-Id: I3ef7051e85601a4440f02cb4dfe2e15227a06e87
parent 0dec660c
......@@ -52,8 +52,18 @@
static inline int sizeofFastQuad(int numPts)
{
// account for size of ptArray
return static_cast<int>(sizeof(vtkFastGeomQuad)+(numPts-4)*sizeof(vtkIdType));
const int qsize = sizeof(vtkFastGeomQuad);
const int sizeId = sizeof(vtkIdType);
// If necessary, we create padding after vtkFastGeomQuad such that
// the beginning of ids aligns evenly with sizeof(vtkIdType).
if (qsize % sizeId == 0)
{
return static_cast<int>(qsize+numPts*sizeId);
}
else
{
return static_cast<int>((qsize/sizeId+1+numPts)*sizeId);
}
}
class vtkDataSetSurfaceFilter::vtkEdgeInterpolationMap
......@@ -2315,6 +2325,19 @@ vtkFastGeomQuad* vtkDataSetSurfaceFilter::NewFastGeomQuad(int numPts)
(this->FastGeomQuadArrays[this->NextArrayIndex] + this->NextQuadIndex);
q->numPts = numPts;
const int qsize = sizeof(vtkFastGeomQuad);
const int sizeId = sizeof(vtkIdType);
// If necessary, we create padding after vtkFastGeomQuad such that
// the beginning of ids aligns evenly with sizeof(vtkIdType).
if (qsize % sizeId == 0)
{
q->ptArray = (vtkIdType*)q + qsize/sizeId;
}
else
{
q->ptArray = (vtkIdType*)q + qsize/sizeId + 1;
}
this->NextQuadIndex += polySize;
return q;
......
......@@ -40,7 +40,7 @@ struct vtkFastGeomQuadStruct
struct vtkFastGeomQuadStruct *Next;
vtkIdType SourceId;
int numPts;
vtkIdType ptArray[4]; // actually a variable length array. MUST be last
vtkIdType* ptArray;
};
typedef struct vtkFastGeomQuadStruct vtkFastGeomQuad;
//ETX
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment