Skip to content

Commit

Permalink
DOC: Add warning to PointSet::SetPoints(PointsVectorContainer *)
Browse files Browse the repository at this point in the history
Aims to mitigate issue #4848
"`PointSet::SetPoints(PointsVectorContainer *)` overload leads to undefined behavior"
  • Loading branch information
N-Dekker authored and dzenanz committed Sep 20, 2024
1 parent 08ff78c commit a995532
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Modules/Core/Common/include/itkPointSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ class ITK_TEMPLATE_EXPORT PointSet : public DataObject
void
SetPoints(PointsContainer *);

/** Set the points container using a 1D vector. */
/** Set the points container using a 1D vector.
\warning This member function is unsafe. It may just work, but it may also lead to undefined behavior. */
void
SetPoints(PointsVectorContainer *);

Expand Down
2 changes: 2 additions & 0 deletions Modules/Core/Common/include/itkPointSet.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ PointSet<TPixelType, VDimension, TMeshTraits>::SetPoints(PointsVectorContainer *
{
itkExceptionMacro("Number of entries in given 1d array incompatible with the point dimension");
}

// Note: this cast is unsafe. It may lead to undefined behavior.
auto * pointsPtr = reinterpret_cast<PointsContainer *>(points);

m_PointsContainer = pointsPtr;
Expand Down

0 comments on commit a995532

Please sign in to comment.