🚨 fix warnings

This commit is contained in:
Niels Lohmann 2020-07-20 22:38:00 +02:00
parent 4a5277d09d
commit a9117828e1
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
5 changed files with 34 additions and 32 deletions

View file

@ -2012,36 +2012,37 @@ class binary_reader
}
// get number string
std::string s;
std::vector<char_int_type> 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<std::string>(s));
auto l = detail::lexer<BasicJsonType, decltype(ia)>(std::move(ia), false);
const auto result_number = l.scan();
const auto result_remainder = l.scan();
auto number_ia = detail::input_adapter(std::forward<decltype(number_vector)>(number_vector));
auto number_lexer = detail::lexer<BasicJsonType, decltype(number_ia)>(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<BasicJsonType>::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")));
}
}

View file

@ -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<std::uint8_t>(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<std::uint8_t>(number[i])));
}
}
// LCOV_EXCL_STOP

View file

@ -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);
}

View file

@ -9512,36 +9512,37 @@ class binary_reader
}
// get number string
std::string s;
std::vector<char_int_type> 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<std::string>(s));
auto l = detail::lexer<BasicJsonType, decltype(ia)>(std::move(ia), false);
const auto result_number = l.scan();
const auto result_remainder = l.scan();
auto number_ia = detail::input_adapter(std::forward<decltype(number_vector)>(number_vector));
auto number_lexer = detail::lexer<BasicJsonType, decltype(number_ia)>(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<BasicJsonType>::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<std::uint8_t>(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<std::uint8_t>(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);
}

View file

@ -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<std::uint8_t>
{
0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4
})
{
// add tag to value
auto v_tagged = v;