diff --git a/include/nlohmann/detail/input/input_adapters.hpp b/include/nlohmann/detail/input/input_adapters.hpp index bc1340a02..05fd4c816 100644 --- a/include/nlohmann/detail/input/input_adapters.hpp +++ b/include/nlohmann/detail/input/input_adapters.hpp @@ -109,7 +109,8 @@ class token_carry_buffer void append(const char* first, const char* last) { const auto n = static_cast(last - first); - if (n > static_cast(m_capacity_end - m_end)) + const auto room = static_cast(m_capacity_end - m_end); + if (n > room) { grow(n); } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index aea492e55..51661ab17 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -8574,7 +8574,8 @@ class token_carry_buffer void append(const char* first, const char* last) { const auto n = static_cast(last - first); - if (n > static_cast(m_capacity_end - m_end)) + const auto room = static_cast(m_capacity_end - m_end); + if (n > room) { grow(n); }