diff --git a/include/nlohmann/detail/input/binary_reader.hpp b/include/nlohmann/detail/input/binary_reader.hpp index 693f078c..6f06856a 100644 --- a/include/nlohmann/detail/input/binary_reader.hpp +++ b/include/nlohmann/detail/input/binary_reader.hpp @@ -2012,36 +2012,37 @@ class binary_reader } // get number string - std::string s; + std::vector number_vector; for (std::size_t i = 0; i < size; ++i) { get(); - s.push_back(current); + number_vector.push_back(current); } // parse number string - auto ia = detail::input_adapter(std::forward(s)); - auto l = detail::lexer(std::move(ia), false); - const auto result_number = l.scan(); - const auto result_remainder = l.scan(); + auto number_ia = detail::input_adapter(std::forward(number_vector)); + auto number_lexer = detail::lexer(std::move(number_ia), false); + const auto result_number = number_lexer.scan(); + const auto number_string = number_lexer.get_token_string(); + const auto result_remainder = number_lexer.scan(); using token_type = typename detail::lexer_base::token_type; if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input)) { - return sax->parse_error(chars_read, s, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson, "invalid number text: " + s, "high-precision number"))); + return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson, "invalid number text: " + number_lexer.get_token_string(), "high-precision number"))); } switch (result_number) { case token_type::value_integer: - return sax->number_integer(l.get_number_integer()); + return sax->number_integer(number_lexer.get_number_integer()); case token_type::value_unsigned: - return sax->number_unsigned(l.get_number_unsigned()); + return sax->number_unsigned(number_lexer.get_number_unsigned()); case token_type::value_float: - return sax->number_float(l.get_number_float(), std::move(s)); + return sax->number_float(number_lexer.get_number_float(), std::move(number_string)); default: - return sax->parse_error(chars_read, s, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson, "invalid number text: " + s, "high-precision number"))); + return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson, "invalid number text: " + number_lexer.get_token_string(), "high-precision number"))); } } diff --git a/include/nlohmann/detail/output/binary_writer.hpp b/include/nlohmann/detail/output/binary_writer.hpp index b707f772..8b864b57 100644 --- a/include/nlohmann/detail/output/binary_writer.hpp +++ b/include/nlohmann/detail/output/binary_writer.hpp @@ -1328,7 +1328,7 @@ class binary_writer write_number_with_ubjson_prefix(number.size(), true); for (std::size_t i = 0; i < number.size(); ++i) { - oa->write_character(to_char_type(number[i])); + oa->write_character(to_char_type(static_cast(number[i]))); } } } @@ -1392,7 +1392,7 @@ class binary_writer write_number_with_ubjson_prefix(number.size(), true); for (std::size_t i = 0; i < number.size(); ++i) { - oa->write_character(to_char_type(number[i])); + oa->write_character(to_char_type(static_cast(number[i]))); } } // LCOV_EXCL_STOP diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index e9f57795..19cf0e9c 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -7507,7 +7507,7 @@ class basic_json const bool allow_exceptions = true, const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) { - return from_cbor(ptr, ptr + len, strict, tag_handler); + return from_cbor(ptr, ptr + len, strict, allow_exceptions, tag_handler); } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 30e994a3..0b9c4edb 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -9512,36 +9512,37 @@ class binary_reader } // get number string - std::string s; + std::vector number_vector; for (std::size_t i = 0; i < size; ++i) { get(); - s.push_back(current); + number_vector.push_back(current); } // parse number string - auto ia = detail::input_adapter(std::forward(s)); - auto l = detail::lexer(std::move(ia), false); - const auto result_number = l.scan(); - const auto result_remainder = l.scan(); + auto number_ia = detail::input_adapter(std::forward(number_vector)); + auto number_lexer = detail::lexer(std::move(number_ia), false); + const auto result_number = number_lexer.scan(); + const auto number_string = number_lexer.get_token_string(); + const auto result_remainder = number_lexer.scan(); using token_type = typename detail::lexer_base::token_type; if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input)) { - return sax->parse_error(chars_read, s, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson, "invalid number text: " + s, "high-precision number"))); + return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson, "invalid number text: " + number_lexer.get_token_string(), "high-precision number"))); } switch (result_number) { case token_type::value_integer: - return sax->number_integer(l.get_number_integer()); + return sax->number_integer(number_lexer.get_number_integer()); case token_type::value_unsigned: - return sax->number_unsigned(l.get_number_unsigned()); + return sax->number_unsigned(number_lexer.get_number_unsigned()); case token_type::value_float: - return sax->number_float(l.get_number_float(), std::move(s)); + return sax->number_float(number_lexer.get_number_float(), std::move(number_string)); default: - return sax->parse_error(chars_read, s, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson, "invalid number text: " + s, "high-precision number"))); + return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson, "invalid number text: " + number_lexer.get_token_string(), "high-precision number"))); } } @@ -13898,7 +13899,7 @@ class binary_writer write_number_with_ubjson_prefix(number.size(), true); for (std::size_t i = 0; i < number.size(); ++i) { - oa->write_character(to_char_type(number[i])); + oa->write_character(to_char_type(static_cast(number[i]))); } } } @@ -13962,7 +13963,7 @@ class binary_writer write_number_with_ubjson_prefix(number.size(), true); for (std::size_t i = 0; i < number.size(); ++i) { - oa->write_character(to_char_type(number[i])); + oa->write_character(to_char_type(static_cast(number[i]))); } } // LCOV_EXCL_STOP @@ -23740,7 +23741,7 @@ class basic_json const bool allow_exceptions = true, const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) { - return from_cbor(ptr, ptr + len, strict, tag_handler); + return from_cbor(ptr, ptr + len, strict, allow_exceptions, tag_handler); } diff --git a/test/src/unit-cbor.cpp b/test/src/unit-cbor.cpp index 2aeac10d..ee32983a 100644 --- a/test/src/unit-cbor.cpp +++ b/test/src/unit-cbor.cpp @@ -2558,10 +2558,10 @@ TEST_CASE("Tagged values") SECTION("0xC6..0xD4") { - for (std::uint8_t b : - { - 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4 - }) + for (auto b : std::vector + { + 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4 + }) { // add tag to value auto v_tagged = v;