From 33ea793020d57dc5d9ea981c649572b7d6d9d435 Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Thu, 19 Nov 2020 22:31:37 -0800 Subject: [PATCH] Avoid the need for floating point arithmetic closes #2124 --- CHANGELOG.md | 1 + include/boost/beast/core/impl/multi_buffer.hpp | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 011f1f26..220923e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +* Remove floating point arithmetic requirement. * Add `cxxstd` to json field. -------------------------------------------------------------------------------- diff --git a/include/boost/beast/core/impl/multi_buffer.hpp b/include/boost/beast/core/impl/multi_buffer.hpp index 510d1265..8565b09f 100644 --- a/include/boost/beast/core/impl/multi_buffer.hpp +++ b/include/boost/beast/core/impl/multi_buffer.hpp @@ -912,15 +912,17 @@ prepare(size_type n) -> destroy(reuse); if(n > 0) { - auto const growth_factor = 2.0f; + std::size_t const growth_factor = 2; + std::size_t altn = in_size_ * growth_factor; + // Overflow detection: + if(in_size_ > altn) + altn = std::numeric_limits::max(); + else + altn = (std::max)(512, altn); auto const size = (std::min)( max_ - total, - (std::max)({ - static_cast( - in_size_ * growth_factor - in_size_), - 512, - n})); + (std::max)(n, altn)); auto& e = alloc(size); list_.push_back(e); if(out_ == list_.end())