diff --git a/include/nlohmann/detail/view/builder.hpp b/include/nlohmann/detail/view/builder.hpp index 2e0151b31..8393b9c8d 100644 --- a/include/nlohmann/detail/view/builder.hpp +++ b/include/nlohmann/detail/view/builder.hpp @@ -195,8 +195,9 @@ class builder { const std::uint64_t done = static_cast(at - b) + 1; const std::uint64_t guess = static_cast(n) * static_cast(e - b + 1) / done; + const std::uint64_t grown = guess + (guess / 4) + 64; // a variable: GCC calls a cast of the sum useless where std::uint64_t is std::size_t doc.tape_size = n; - doc.reserve((std::max)(static_cast(guess + (guess / 4) + 64), n + (n / 2) + 64)); + doc.reserve((std::max)(static_cast(grown), n + (n / 2) + 64)); return doc.tape; } diff --git a/include/nlohmann/detail/view/pointer.hpp b/include/nlohmann/detail/view/pointer.hpp index 2c7b1e4db..d2ac497d7 100644 --- a/include/nlohmann/detail/view/pointer.hpp +++ b/include/nlohmann/detail/view/pointer.hpp @@ -69,7 +69,7 @@ index_status array_index(const StringType& s, std::size_t& idx) noexcept } v = (v * 10) + d; } - if (v >= static_cast((std::numeric_limits::max)())) + if (v >= (std::numeric_limits::max)()) // (std::size_t converts to std::uint64_t implicitly) { return index_status::too_large; } diff --git a/single_include/nlohmann/json_view.hpp b/single_include/nlohmann/json_view.hpp index 005079300..63a54c918 100644 --- a/single_include/nlohmann/json_view.hpp +++ b/single_include/nlohmann/json_view.hpp @@ -739,8 +739,9 @@ class builder { const std::uint64_t done = static_cast(at - b) + 1; const std::uint64_t guess = static_cast(n) * static_cast(e - b + 1) / done; + const std::uint64_t grown = guess + (guess / 4) + 64; // a variable: GCC calls a cast of the sum useless where std::uint64_t is std::size_t doc.tape_size = n; - doc.reserve((std::max)(static_cast(guess + (guess / 4) + 64), n + (n / 2) + 64)); + doc.reserve((std::max)(static_cast(grown), n + (n / 2) + 64)); return doc.tape; } @@ -2466,7 +2467,7 @@ index_status array_index(const StringType& s, std::size_t& idx) noexcept } v = (v * 10) + d; } - if (v >= static_cast((std::numeric_limits::max)())) + if (v >= (std::numeric_limits::max)()) // (std::size_t converts to std::uint64_t implicitly) { return index_status::too_large; }