diff --git a/Eigen/src/SparseCore/CompressedStorage.h b/Eigen/src/SparseCore/CompressedStorage.h index 123c89c0d..8f8a6963a 100644 --- a/Eigen/src/SparseCore/CompressedStorage.h +++ b/Eigen/src/SparseCore/CompressedStorage.h @@ -71,8 +71,13 @@ class CompressedStorage { void resize(Index size, double reserveSizeFactor = 0) { if (m_allocatedSize < size) { + // Avoid underflow on the std::min call by choosing the smaller index type. + using SmallerIndexType = + typename std::conditional((std::numeric_limits::max)()) < + static_cast((std::numeric_limits::max)()), + Index, StorageIndex>::type; Index realloc_size = - (std::min)(NumTraits::highest(), size + Index(reserveSizeFactor * double(size))); + (std::min)(NumTraits::highest(), size + Index(reserveSizeFactor * double(size))); if (realloc_size < size) internal::throw_std_bad_alloc(); reallocate(realloc_size); }