From a99553204c60e7114900e2778c9d7bd0b7156b50 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Tue, 17 Sep 2024 17:23:22 +0200 Subject: [PATCH] DOC: Add warning to `PointSet::SetPoints(PointsVectorContainer *)` Aims to mitigate issue https://github.com/InsightSoftwareConsortium/ITK/issues/4848 "`PointSet::SetPoints(PointsVectorContainer *)` overload leads to undefined behavior" --- Modules/Core/Common/include/itkPointSet.h | 3 ++- Modules/Core/Common/include/itkPointSet.hxx | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Modules/Core/Common/include/itkPointSet.h b/Modules/Core/Common/include/itkPointSet.h index 9b8f6d75e94..aeb3db8defe 100644 --- a/Modules/Core/Common/include/itkPointSet.h +++ b/Modules/Core/Common/include/itkPointSet.h @@ -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 *); diff --git a/Modules/Core/Common/include/itkPointSet.hxx b/Modules/Core/Common/include/itkPointSet.hxx index 0aed6b93cae..f4731b7d441 100644 --- a/Modules/Core/Common/include/itkPointSet.hxx +++ b/Modules/Core/Common/include/itkPointSet.hxx @@ -73,6 +73,8 @@ PointSet::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(points); m_PointsContainer = pointsPtr;