aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core/util
diff options
context:
space:
mode:
authorGravatar Antonio Sanchez <cantonios@google.com>2021-04-21 15:45:31 -0700
committerGravatar Rasmus Munk Larsen <rmlarsen@google.com>2021-04-22 18:45:19 +0000
commitd213a0bcea2344aa3f6c9856da9f5b2a26ccec25 (patch)
tree2cc3668db7d8928455a0e051d6373873ba4a316e /Eigen/src/Core/util
parent85a76a16ea835fcfa7d4c185a338ae2aef9a272a (diff)
DenseStorage safely copy/swap.
Fixes #2229. For dynamic matrices with fixed-sized storage, only copy/swap elements that have been set. Otherwise, this leads to inefficient copying, and potential UB for non-initialized elements.
Diffstat (limited to 'Eigen/src/Core/util')
-rw-r--r--Eigen/src/Core/util/Memory.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/Eigen/src/Core/util/Memory.h b/Eigen/src/Core/util/Memory.h
index 7cbe8a672..875318cdb 100644
--- a/Eigen/src/Core/util/Memory.h
+++ b/Eigen/src/Core/util/Memory.h
@@ -566,6 +566,17 @@ template<typename T> struct smart_memmove_helper<T,false> {
}
};
+#if EIGEN_HAS_RVALUE_REFERENCES
+template<typename T> EIGEN_DEVICE_FUNC T* smart_move(T* start, T* end, T* target)
+{
+ return std::move(start, end, target);
+}
+#else
+template<typename T> EIGEN_DEVICE_FUNC T* smart_move(T* start, T* end, T* target)
+{
+ return std::copy(start, end, target);
+}
+#endif
/*****************************************************************************
*** Implementation of runtime stack allocation (falling back to malloc) ***