Eliminate possible -Wstringop-overflow warning in .setZero()

This commit is contained in:
Sergiu Deitsch 2025-10-04 00:03:03 +02:00
parent 1edf360e3c
commit 32b0f386bc
No known key found for this signature in database

View File

@ -115,17 +115,15 @@ struct eigen_zero_impl<Xpr, /*use_memset*/ false> {
template <typename Xpr>
struct eigen_zero_impl<Xpr, /*use_memset*/ true> {
using Scalar = typename Xpr::Scalar;
static constexpr size_t max_bytes = (std::numeric_limits<std::ptrdiff_t>::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<std::ptrdiff_t>(sizeof(Scalar));
if (num_bytes <= 0) return;
void* dst_ptr = static_cast<void*>(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<std::size_t>(num_bytes));
}
template <typename SrcXpr>
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Xpr& dst, const SrcXpr& src) {