From 32b0f386bcb20b7a2fae6351683aeb59b99cdd8d Mon Sep 17 00:00:00 2001 From: Sergiu Deitsch Date: Sat, 4 Oct 2025 00:03:03 +0200 Subject: [PATCH] Eliminate possible -Wstringop-overflow warning in .setZero() --- Eigen/src/Core/Fill.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Eigen/src/Core/Fill.h b/Eigen/src/Core/Fill.h index f40d56db6..779ef26ab 100644 --- a/Eigen/src/Core/Fill.h +++ b/Eigen/src/Core/Fill.h @@ -115,17 +115,15 @@ struct eigen_zero_impl { template struct eigen_zero_impl { using Scalar = typename Xpr::Scalar; - static constexpr size_t max_bytes = (std::numeric_limits::max)(); static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Xpr& dst) { - const size_t num_bytes = dst.size() * sizeof(Scalar); - if (num_bytes == 0) return; + const std::ptrdiff_t num_bytes = dst.size() * static_cast(sizeof(Scalar)); + if (num_bytes <= 0) return; void* dst_ptr = static_cast(dst.data()); #ifndef EIGEN_NO_DEBUG - if (num_bytes > max_bytes) throw_std_bad_alloc(); eigen_assert((dst_ptr != nullptr) && "null pointer dereference error!"); #endif EIGEN_USING_STD(memset); - memset(dst_ptr, 0, num_bytes); + memset(dst_ptr, 0, static_cast(num_bytes)); } template static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Xpr& dst, const SrcXpr& src) {