mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-10-11 15:41:30 +08:00
Eliminate possible -Wstringop-overflow warning in .setZero()
This commit is contained in:
parent
1edf360e3c
commit
32b0f386bc
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user