diff --git a/Eigen/src/Core/util/Memory.h b/Eigen/src/Core/util/Memory.h index bc1ea69ed..c3871dbd3 100644 --- a/Eigen/src/Core/util/Memory.h +++ b/Eigen/src/Core/util/Memory.h @@ -507,7 +507,12 @@ template void smart_copy(const T* start, const T* end, T* target) template struct smart_copy_helper { static inline void run(const T* start, const T* end, T* target) - { memcpy(target, start, std::ptrdiff_t(end)-std::ptrdiff_t(start)); } + { + std::ptrdiff_t size = std::ptrdiff_t(end)-std::ptrdiff_t(start); + if(size==0) return; + eigen_internal_assert(start!=0 && end!=0 && target!=0); + memcpy(target, start, size); + } }; template struct smart_copy_helper { @@ -515,7 +520,6 @@ template struct smart_copy_helper { { std::copy(start, end, target); } }; - /***************************************************************************** *** Implementation of runtime stack allocation (falling back to malloc) *** *****************************************************************************/