🚨 fix UBSAN warnings
This commit is contained in:
parent
0db1692f45
commit
dfe53c36da
4 changed files with 30 additions and 25 deletions
|
@ -584,10 +584,9 @@ TEST_CASE("BSON input/output_adapters")
|
||||||
{
|
{
|
||||||
SECTION("std::ostringstream")
|
SECTION("std::ostringstream")
|
||||||
{
|
{
|
||||||
std::ostringstream ss;
|
std::basic_ostringstream<std::uint8_t> ss;
|
||||||
json::to_bson(json_representation, ss);
|
json::to_bson(json_representation, ss);
|
||||||
std::istringstream iss(ss.str());
|
json j3 = json::from_bson(ss.str());
|
||||||
json j3 = json::from_bson(iss);
|
|
||||||
CHECK(json_representation == j3);
|
CHECK(json_representation == j3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1580,7 +1580,7 @@ TEST_CASE("single CBOR roundtrip")
|
||||||
{
|
{
|
||||||
SECTION("std::ostringstream")
|
SECTION("std::ostringstream")
|
||||||
{
|
{
|
||||||
std::ostringstream ss;
|
std::basic_ostringstream<std::uint8_t> ss;
|
||||||
json::to_cbor(j1, ss);
|
json::to_cbor(j1, ss);
|
||||||
json j3 = json::from_cbor(ss.str());
|
json j3 = json::from_cbor(ss.str());
|
||||||
CHECK(j1 == j3);
|
CHECK(j1 == j3);
|
||||||
|
|
|
@ -1334,7 +1334,7 @@ TEST_CASE("single MessagePack roundtrip")
|
||||||
{
|
{
|
||||||
SECTION("std::ostringstream")
|
SECTION("std::ostringstream")
|
||||||
{
|
{
|
||||||
std::ostringstream ss;
|
std::basic_ostringstream<std::uint8_t> ss;
|
||||||
json::to_msgpack(j1, ss);
|
json::to_msgpack(j1, ss);
|
||||||
json j3 = json::from_msgpack(ss.str());
|
json j3 = json::from_msgpack(ss.str());
|
||||||
CHECK(j1 == j3);
|
CHECK(j1 == j3);
|
||||||
|
|
|
@ -1749,31 +1749,37 @@ TEST_CASE("regression tests")
|
||||||
{
|
{
|
||||||
SECTION("a bunch of -1, ensure_ascii=true")
|
SECTION("a bunch of -1, ensure_ascii=true")
|
||||||
{
|
{
|
||||||
|
const auto length = 300;
|
||||||
|
|
||||||
json dump_test;
|
json dump_test;
|
||||||
std::vector<char> data(300, -1);
|
dump_test["1"] = std::string(length, -1);
|
||||||
std::vector<std::string> vec_string(300, "\\ufffd");
|
|
||||||
std::string s{data.data(), data.size()};
|
std::string expected = "{\"1\":\"";
|
||||||
dump_test["1"] = s;
|
for (int i = 0; i < length; ++i)
|
||||||
std::ostringstream os;
|
{
|
||||||
os << "{\"1\":\"";
|
expected += "\\ufffd";
|
||||||
std::copy( vec_string.begin(), vec_string.end(), std::ostream_iterator<std::string>(os));
|
}
|
||||||
os << "\"}";
|
expected += "\"}";
|
||||||
s = dump_test.dump(-1, ' ', true, nlohmann::json::error_handler_t::replace);
|
|
||||||
CHECK(s == os.str());
|
auto s = dump_test.dump(-1, ' ', true, nlohmann::json::error_handler_t::replace);
|
||||||
|
CHECK(s == expected);
|
||||||
}
|
}
|
||||||
SECTION("a bunch of -2, ensure_ascii=false")
|
SECTION("a bunch of -2, ensure_ascii=false")
|
||||||
{
|
{
|
||||||
|
const auto length = 500;
|
||||||
|
|
||||||
json dump_test;
|
json dump_test;
|
||||||
std::vector<char> data(500, -2);
|
dump_test["1"] = std::string(length, -2);
|
||||||
std::vector<std::string> vec_string(500, "\xEF\xBF\xBD");
|
|
||||||
std::string s{data.data(), data.size()};
|
std::string expected = "{\"1\":\"";
|
||||||
dump_test["1"] = s;
|
for (int i = 0; i < length; ++i)
|
||||||
std::ostringstream os;
|
{
|
||||||
os << "{\"1\":\"";
|
expected += "\xEF\xBF\xBD";
|
||||||
std::copy( vec_string.begin(), vec_string.end(), std::ostream_iterator<std::string>(os));
|
}
|
||||||
os << "\"}";
|
expected += "\"}";
|
||||||
s = dump_test.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace);
|
|
||||||
CHECK(s == os.str());
|
auto s = dump_test.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace);
|
||||||
|
CHECK(s == expected);
|
||||||
}
|
}
|
||||||
SECTION("test case in issue #1445")
|
SECTION("test case in issue #1445")
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue