Avoid bigint_cast stack overflow

This commit is contained in:
fenglv 2020-11-22 03:42:16 +00:00
parent 268b15f221
commit 615287ae75

View File

@ -239,6 +239,13 @@ struct integer<Bits, Signed>::_impl
template <class T>
constexpr static void set_multiplier(integer<Bits, Signed> & self, T t) noexcept {
constexpr uint64_t max_int = std::numeric_limits<uint64_t>::max();
/// Replacing nan to zero, and inf to max(T) to avoid stack overflow in bigint_cast
if (isnan(t))
t = 0;
if (isinf(t))
t = std::numeric_limits<T>::max();
const T alpha = t / max_int;
if (alpha <= max_int)