diff --git a/Modules/Core/Common/include/itkVector.h b/Modules/Core/Common/include/itkVector.h index 02fd8fec3284..8a5e1cdf8af8 100644 --- a/Modules/Core/Common/include/itkVector.h +++ b/Modules/Core/Common/include/itkVector.h @@ -90,7 +90,8 @@ class ITK_TEMPLATE_EXPORT Vector : public FixedArray return VVectorDimension; } - /** Set a vnl_vector_ref referencing the same memory block. */ + /** Copy values from the vnl_vector input to the internal memory block. The minimum of + * VVectorDimension and vnl_vector::size() elements are copied. */ void SetVnlVector(const vnl_vector &); diff --git a/Modules/Core/Common/include/itkVector.hxx b/Modules/Core/Common/include/itkVector.hxx index 408a9d8cb4f6..8d2fca35141b 100644 --- a/Modules/Core/Common/include/itkVector.hxx +++ b/Modules/Core/Common/include/itkVector.hxx @@ -155,7 +155,8 @@ template void Vector::SetVnlVector(const vnl_vector & v) { - for (unsigned int i = 0; i < v.size(); ++i) + const unsigned int elements_to_copy = std::min(TVectorDimension, v.size()); + for (unsigned int i = 0; i < elements_to_copy; ++i) { (*this)[i] = v(i); }