1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-22 15:21:52 +03:00

🔨 fixed some pedantic GCC warnings

This commit is contained in:
Niels Lohmann
2017-07-07 22:41:22 +02:00
parent 32065c8045
commit 8b123107c0
22 changed files with 747 additions and 744 deletions

View File

@ -572,7 +572,7 @@ TEST_CASE("regression tests")
SECTION("issue #329 - serialized value not always can be parsed")
{
CHECK_THROWS_AS(json::parse("22e2222"), json::out_of_range);
CHECK_THROWS_AS(json::parse("22e2222"), json::out_of_range&);
CHECK_THROWS_WITH(json::parse("22e2222"),
"[json.exception.out_of_range.406] number overflow parsing '22e2222'");
}
@ -580,7 +580,7 @@ TEST_CASE("regression tests")
SECTION("issue #366 - json::parse on failed stream gets stuck")
{
std::ifstream f("file_not_found.json");
CHECK_THROWS_AS(json::parse(f), json::parse_error);
CHECK_THROWS_AS(json::parse(f), json::parse_error&);
CHECK_THROWS_WITH(json::parse(f), "[json.exception.parse_error.111] parse error: bad input stream");
}
@ -595,7 +595,7 @@ TEST_CASE("regression tests")
// ss is not at EOF; this yielded an error before the fix
// (threw basic_string::append). No, it should just throw
// a parse error because of the EOF.
CHECK_THROWS_AS(ss >> j, json::parse_error);
CHECK_THROWS_AS(ss >> j, json::parse_error&);
CHECK_THROWS_WITH(ss >> j,
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input; expected '[', '{', or a literal");
}
@ -606,7 +606,7 @@ TEST_CASE("regression tests")
{
std::stringstream ss;
json j;
CHECK_THROWS_AS(ss >> j, json::parse_error);
CHECK_THROWS_AS(ss >> j, json::parse_error&);
CHECK_THROWS_WITH(ss >> j,
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input; expected '[', '{', or a literal");
}
@ -616,7 +616,7 @@ TEST_CASE("regression tests")
std::stringstream ss;
ss << " ";
json j;
CHECK_THROWS_AS(ss >> j, json::parse_error);
CHECK_THROWS_AS(ss >> j, json::parse_error&);
CHECK_THROWS_WITH(ss >> j,
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input; expected '[', '{', or a literal");
}
@ -629,7 +629,7 @@ TEST_CASE("regression tests")
CHECK_NOTHROW(ss >> j);
CHECK(j == 111);
CHECK_THROWS_AS(ss >> j, json::parse_error);
CHECK_THROWS_AS(ss >> j, json::parse_error&);
CHECK_THROWS_WITH(ss >> j,
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input; expected '[', '{', or a literal");
}
@ -642,7 +642,7 @@ TEST_CASE("regression tests")
CHECK_NOTHROW(ss >> j);
CHECK(j == 222);
CHECK_THROWS_AS(ss >> j, json::parse_error);
CHECK_THROWS_AS(ss >> j, json::parse_error&);
CHECK_THROWS_WITH(ss >> j,
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input; expected '[', '{', or a literal");
}
@ -655,7 +655,7 @@ TEST_CASE("regression tests")
CHECK_NOTHROW(ss >> j);
CHECK(j == 333);
CHECK_THROWS_AS(ss >> j, json::parse_error);
CHECK_THROWS_AS(ss >> j, json::parse_error&);
CHECK_THROWS_WITH(ss >> j,
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input; expected '[', '{', or a literal");
}
@ -672,7 +672,7 @@ TEST_CASE("regression tests")
CHECK_NOTHROW(ss >> j);
CHECK(j == 333);
CHECK_THROWS_AS(ss >> j, json::parse_error);
CHECK_THROWS_AS(ss >> j, json::parse_error&);
CHECK_THROWS_WITH(ss >> j,
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input; expected '[', '{', or a literal");
}
@ -691,7 +691,7 @@ TEST_CASE("regression tests")
CHECK_NOTHROW(ss >> j);
CHECK(j == "");
CHECK_THROWS_AS(ss >> j, json::parse_error);
CHECK_THROWS_AS(ss >> j, json::parse_error&);
CHECK_THROWS_WITH(ss >> j,
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input; expected '[', '{', or a literal");
}
@ -706,7 +706,7 @@ TEST_CASE("regression tests")
CHECK_NOTHROW(ss >> j);
CHECK(j == json({{"three", 3}}));
CHECK_THROWS_AS(ss >> j, json::parse_error);
CHECK_THROWS_AS(ss >> j, json::parse_error&);
CHECK_THROWS_WITH(ss >> j,
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input; expected '[', '{', or a literal");
}
@ -776,7 +776,7 @@ TEST_CASE("regression tests")
{
// original test case
std::vector<uint8_t> vec {0x65, 0xf5, 0x0a, 0x48, 0x21};
CHECK_THROWS_AS(json::from_cbor(vec), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(vec), json::parse_error&);
CHECK_THROWS_WITH(json::from_cbor(vec),
"[json.exception.parse_error.110] parse error at 6: unexpected end of input");
}
@ -785,31 +785,31 @@ TEST_CASE("regression tests")
{
// original test case: incomplete float64
std::vector<uint8_t> vec1 {0xcb, 0x8f, 0x0a};
CHECK_THROWS_AS(json::from_msgpack(vec1), json::parse_error);
CHECK_THROWS_AS(json::from_msgpack(vec1), json::parse_error&);
CHECK_THROWS_WITH(json::from_msgpack(vec1),
"[json.exception.parse_error.110] parse error at 4: unexpected end of input");
// related test case: incomplete float32
std::vector<uint8_t> vec2 {0xca, 0x8f, 0x0a};
CHECK_THROWS_AS(json::from_msgpack(vec2), json::parse_error);
CHECK_THROWS_AS(json::from_msgpack(vec2), json::parse_error&);
CHECK_THROWS_WITH(json::from_msgpack(vec2),
"[json.exception.parse_error.110] parse error at 4: unexpected end of input");
// related test case: incomplete Half-Precision Float (CBOR)
std::vector<uint8_t> vec3 {0xf9, 0x8f};
CHECK_THROWS_AS(json::from_cbor(vec3), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(vec3), json::parse_error&);
CHECK_THROWS_WITH(json::from_cbor(vec3),
"[json.exception.parse_error.110] parse error at 3: unexpected end of input");
// related test case: incomplete Single-Precision Float (CBOR)
std::vector<uint8_t> vec4 {0xfa, 0x8f, 0x0a};
CHECK_THROWS_AS(json::from_cbor(vec4), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(vec4), json::parse_error&);
CHECK_THROWS_WITH(json::from_cbor(vec4),
"[json.exception.parse_error.110] parse error at 4: unexpected end of input");
// related test case: incomplete Double-Precision Float (CBOR)
std::vector<uint8_t> vec5 {0xfb, 0x8f, 0x0a};
CHECK_THROWS_AS(json::from_cbor(vec5), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(vec5), json::parse_error&);
CHECK_THROWS_WITH(json::from_cbor(vec5),
"[json.exception.parse_error.110] parse error at 4: unexpected end of input");
}
@ -818,7 +818,7 @@ TEST_CASE("regression tests")
{
// original test case
std::vector<uint8_t> vec1 {0x87};
CHECK_THROWS_AS(json::from_msgpack(vec1), json::parse_error);
CHECK_THROWS_AS(json::from_msgpack(vec1), json::parse_error&);
CHECK_THROWS_WITH(json::from_msgpack(vec1),
"[json.exception.parse_error.110] parse error at 2: unexpected end of input");
@ -832,7 +832,7 @@ TEST_CASE("regression tests")
})
{
std::vector<uint8_t> vec(1, static_cast<uint8_t>(b));
CHECK_THROWS_AS(json::from_msgpack(vec), json::parse_error);
CHECK_THROWS_AS(json::from_msgpack(vec), json::parse_error&);
}
// more test cases for CBOR
@ -847,15 +847,15 @@ TEST_CASE("regression tests")
})
{
std::vector<uint8_t> vec(1, static_cast<uint8_t>(b));
CHECK_THROWS_AS(json::from_cbor(vec), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(vec), json::parse_error&);
}
// special case: empty input
std::vector<uint8_t> vec2;
CHECK_THROWS_AS(json::from_cbor(vec2), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(vec2), json::parse_error&);
CHECK_THROWS_WITH(json::from_cbor(vec2),
"[json.exception.parse_error.110] parse error at 1: unexpected end of input");
CHECK_THROWS_AS(json::from_msgpack(vec2), json::parse_error);
CHECK_THROWS_AS(json::from_msgpack(vec2), json::parse_error&);
CHECK_THROWS_WITH(json::from_msgpack(vec2),
"[json.exception.parse_error.110] parse error at 1: unexpected end of input");
}
@ -864,19 +864,19 @@ TEST_CASE("regression tests")
{
// original test case: empty UTF-8 string (indefinite length)
std::vector<uint8_t> vec1 {0x7f};
CHECK_THROWS_AS(json::from_cbor(vec1), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(vec1), json::parse_error&);
CHECK_THROWS_WITH(json::from_cbor(vec1),
"[json.exception.parse_error.110] parse error at 2: unexpected end of input");
// related test case: empty array (indefinite length)
std::vector<uint8_t> vec2 {0x9f};
CHECK_THROWS_AS(json::from_cbor(vec2), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(vec2), json::parse_error&);
CHECK_THROWS_WITH(json::from_cbor(vec2),
"[json.exception.parse_error.110] parse error at 2: unexpected end of input");
// related test case: empty map (indefinite length)
std::vector<uint8_t> vec3 {0xbf};
CHECK_THROWS_AS(json::from_cbor(vec3), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(vec3), json::parse_error&);
CHECK_THROWS_WITH(json::from_cbor(vec3),
"[json.exception.parse_error.110] parse error at 2: unexpected end of input");
}
@ -904,25 +904,25 @@ TEST_CASE("regression tests")
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60
};
CHECK_THROWS_AS(json::from_cbor(vec), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(vec), json::parse_error&);
CHECK_THROWS_WITH(json::from_cbor(vec),
"[json.exception.parse_error.113] parse error at 2: expected a CBOR string; last byte: 0x98");
// related test case: nonempty UTF-8 string (indefinite length)
std::vector<uint8_t> vec1 {0x7f, 0x61, 0x61};
CHECK_THROWS_AS(json::from_cbor(vec1), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(vec1), json::parse_error&);
CHECK_THROWS_WITH(json::from_cbor(vec1),
"[json.exception.parse_error.110] parse error at 4: unexpected end of input");
// related test case: nonempty array (indefinite length)
std::vector<uint8_t> vec2 {0x9f, 0x01};
CHECK_THROWS_AS(json::from_cbor(vec2), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(vec2), json::parse_error&);
CHECK_THROWS_WITH(json::from_cbor(vec2),
"[json.exception.parse_error.110] parse error at 3: unexpected end of input");
// related test case: nonempty map (indefinite length)
std::vector<uint8_t> vec3 {0xbf, 0x61, 0x61, 0x01};
CHECK_THROWS_AS(json::from_cbor(vec3), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(vec3), json::parse_error&);
CHECK_THROWS_WITH(json::from_cbor(vec3),
"[json.exception.parse_error.110] parse error at 5: unexpected end of input");
}
@ -957,7 +957,7 @@ TEST_CASE("regression tests")
0x96, 0x96, 0xb4, 0xb4, 0xfa, 0x94, 0x94, 0x61,
0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0xfa
};
CHECK_THROWS_AS(json::from_cbor(vec1), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(vec1), json::parse_error&);
CHECK_THROWS_WITH(json::from_cbor(vec1),
"[json.exception.parse_error.113] parse error at 13: expected a CBOR string; last byte: 0xb4");
@ -971,7 +971,7 @@ TEST_CASE("regression tests")
0x96, 0x96, 0xb4, 0xb4, 0xfa, 0x94, 0x94, 0x61,
0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0xfb
};
CHECK_THROWS_AS(json::from_cbor(vec2), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(vec2), json::parse_error&);
CHECK_THROWS_WITH(json::from_cbor(vec2),
"[json.exception.parse_error.113] parse error at 13: expected a CBOR string; last byte: 0xb4");
}
@ -979,7 +979,7 @@ TEST_CASE("regression tests")
SECTION("issue #452 - Heap-buffer-overflow (OSS-Fuzz issue 585)")
{
std::vector<uint8_t> vec = {'-', '0', '1', '2', '2', '7', '4'};
CHECK_THROWS_AS(json::parse(vec), json::parse_error);
CHECK_THROWS_AS(json::parse(vec), json::parse_error&);
}
SECTION("issue #454 - doubles are printed as integers")
@ -1019,9 +1019,9 @@ TEST_CASE("regression tests")
};
CHECK_NOTHROW(create(j_array));
CHECK_THROWS_AS(create(j_number), json::type_error);
CHECK_THROWS_AS(create(j_number), json::type_error&);
CHECK_THROWS_WITH(create(j_number), "[json.exception.type_error.302] type must be array, but is number");
CHECK_THROWS_AS(create(j_null), json::type_error);
CHECK_THROWS_AS(create(j_null), json::type_error&);
CHECK_THROWS_WITH(create(j_null), "[json.exception.type_error.302] type must be array, but is null");
}
@ -1033,9 +1033,9 @@ TEST_CASE("regression tests")
};
CHECK_NOTHROW(create(j_array));
CHECK_THROWS_AS(create(j_number), json::type_error);
CHECK_THROWS_AS(create(j_number), json::type_error&);
CHECK_THROWS_WITH(create(j_number), "[json.exception.type_error.302] type must be array, but is number");
CHECK_THROWS_AS(create(j_null), json::type_error);
CHECK_THROWS_AS(create(j_null), json::type_error&);
CHECK_THROWS_WITH(create(j_null), "[json.exception.type_error.302] type must be array, but is null");
}
@ -1047,9 +1047,9 @@ TEST_CASE("regression tests")
};
CHECK_NOTHROW(create(j_array));
CHECK_THROWS_AS(create(j_number), json::type_error);
CHECK_THROWS_AS(create(j_number), json::type_error&);
CHECK_THROWS_WITH(create(j_number), "[json.exception.type_error.302] type must be array, but is number");
CHECK_THROWS_AS(create(j_null), json::type_error);
CHECK_THROWS_AS(create(j_null), json::type_error&);
CHECK_THROWS_WITH(create(j_null), "[json.exception.type_error.302] type must be array, but is null");
}
}
@ -1084,7 +1084,7 @@ TEST_CASE("regression tests")
l.m_stream->setstate(std::ios_base::failbit);
CHECK_THROWS_AS(l.fill_line_buffer(), json::parse_error);
CHECK_THROWS_AS(l.fill_line_buffer(), json::parse_error&);
CHECK_THROWS_WITH(l.fill_line_buffer(), "[json.exception.parse_error.111] parse error: bad input stream");
}
@ -1099,7 +1099,7 @@ TEST_CASE("regression tests")
l.m_stream->setstate(std::ios_base::badbit);
CHECK_THROWS_AS(l.fill_line_buffer(), json::parse_error);
CHECK_THROWS_AS(l.fill_line_buffer(), json::parse_error&);
CHECK_THROWS_WITH(l.fill_line_buffer(), "[json.exception.parse_error.111] parse error: bad input stream");
}
}
@ -1163,7 +1163,7 @@ TEST_CASE("regression tests")
SECTION("issue #575 - heap-buffer-overflow (OSS-Fuzz 1400)")
{
std::vector<uint8_t> vec = {'"', '\\', '"', 'X', '"', '"'};
CHECK_THROWS_AS(json::parse(vec), json::parse_error);
CHECK_THROWS_AS(json::parse(vec), json::parse_error&);
}
SECTION("issue #600 - how does one convert a map in Json back to std::map?")