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

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 @@ ...@@ -52,8 +52,18 @@
static inline int sizeofFastQuad(int numPts) static inline int sizeofFastQuad(int numPts)
{ {
// account for size of ptArray const int qsize = sizeof(vtkFastGeomQuad);
return static_cast<int>(sizeof(vtkFastGeomQuad)+(numPts-4)*sizeof(vtkIdType)); 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 class vtkDataSetSurfaceFilter::vtkEdgeInterpolationMap
...@@ -2315,6 +2325,19 @@ vtkFastGeomQuad* vtkDataSetSurfaceFilter::NewFastGeomQuad(int numPts) ...@@ -2315,6 +2325,19 @@ vtkFastGeomQuad* vtkDataSetSurfaceFilter::NewFastGeomQuad(int numPts)
(this->FastGeomQuadArrays[this->NextArrayIndex] + this->NextQuadIndex); (this->FastGeomQuadArrays[this->NextArrayIndex] + this->NextQuadIndex);
q->numPts = numPts; 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; this->NextQuadIndex += polySize;
return q; return q;
......
...@@ -40,7 +40,7 @@ struct vtkFastGeomQuadStruct ...@@ -40,7 +40,7 @@ struct vtkFastGeomQuadStruct
struct vtkFastGeomQuadStruct *Next; struct vtkFastGeomQuadStruct *Next;
vtkIdType SourceId; vtkIdType SourceId;
int numPts; int numPts;
vtkIdType ptArray[4]; // actually a variable length array. MUST be last vtkIdType* ptArray;
}; };
typedef struct vtkFastGeomQuadStruct vtkFastGeomQuad; typedef struct vtkFastGeomQuadStruct vtkFastGeomQuad;
//ETX //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