mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-06-04 18:54:00 +08:00
[Compressed Storage] Use smaller type of Index & StorageIndex for determining maximum size during resize.
This commit is contained in:
parent
772057c558
commit
eede526b7c
@ -71,8 +71,13 @@ class CompressedStorage {
|
||||
|
||||
void resize(Index size, double reserveSizeFactor = 0) {
|
||||
if (m_allocatedSize < size) {
|
||||
// Avoid underflow on the std::min<Index> call by choosing the smaller index type.
|
||||
using SmallerIndexType =
|
||||
typename std::conditional<static_cast<size_t>((std::numeric_limits<Index>::max)()) <
|
||||
static_cast<size_t>((std::numeric_limits<StorageIndex>::max)()),
|
||||
Index, StorageIndex>::type;
|
||||
Index realloc_size =
|
||||
(std::min<Index>)(NumTraits<StorageIndex>::highest(), size + Index(reserveSizeFactor * double(size)));
|
||||
(std::min<Index>)(NumTraits<SmallerIndexType>::highest(), size + Index(reserveSizeFactor * double(size)));
|
||||
if (realloc_size < size) internal::throw_std_bad_alloc();
|
||||
reallocate(realloc_size);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user