diff --git a/include/nlohmann/detail/input/binary_reader.hpp b/include/nlohmann/detail/input/binary_reader.hpp index 5fe19b810..619fe1a4b 100644 --- a/include/nlohmann/detail/input/binary_reader.hpp +++ b/include/nlohmann/detail/input/binary_reader.hpp @@ -2079,7 +2079,7 @@ class binary_reader return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr)); } - if (number > std::numeric_limits::max()) + if (!value_in_range_of(number)) { return sax->parse_error(chars_read, get_token_string(), parse_error::create(408, chars_read, exception_message(input_format, "integer value overflow", "size"), nullptr)); @@ -2129,7 +2129,7 @@ class binary_reader { return false; } - if (number > std::numeric_limits::max()) + if (!value_in_range_of(number)) { return sax->parse_error(chars_read, get_token_string(), parse_error::create(408, chars_read, exception_message(input_format, "integer value overflow", "size"), nullptr)); diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 281f66d88..1314ee7fb 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -10764,7 +10764,7 @@ class binary_reader return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr)); } - if (number > std::numeric_limits::max()) + if (!value_in_range_of(number)) { return sax->parse_error(chars_read, get_token_string(), parse_error::create(408, chars_read, exception_message(input_format, "integer value overflow", "size"), nullptr)); @@ -10814,7 +10814,7 @@ class binary_reader { return false; } - if (number > std::numeric_limits::max()) + if (!value_in_range_of(number)) { return sax->parse_error(chars_read, get_token_string(), parse_error::create(408, chars_read, exception_message(input_format, "integer value overflow", "size"), nullptr));