Fix the msgpack 2^32-1 element recovery test on 32-bit targets

On a 32-bit target (clang-cl Win32) 0xFFFFFFFF elements exceed the
array's max_size(), so the array is rejected before it is started and
the recovered value is null rather than an empty array. Expect that.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann committed 2026-11-09 14:50:46 +01:00
1 parent b6070980a1
commit 2e55a6a08a
1 file changed
+4 -1
+4 -1
View File
@@ -380,9 +380,12 @@ TEST_CASE("regression test - #3989 SAX parse_error() returning true")
CHECK(cbor_map.errors == 1); CHECK(cbor_map.errors == 1);
CHECK(cbor_map.value == json({{"a", nullptr}})); CHECK(cbor_map.value == json({{"a", nullptr}}));
// 2^32-1 elements: on a 32-bit target this exceeds the array's max_size(),
// so the array is rejected before it is started and the value stays null
const auto msgpack_array = parse_binary_recovering({0xDD, 0xFF, 0xFF, 0xFF, 0xFF}, json::input_format_t::msgpack); const auto msgpack_array = parse_binary_recovering({0xDD, 0xFF, 0xFF, 0xFF, 0xFF}, json::input_format_t::msgpack);
const bool msgpack_array_fits = json::array_t().max_size() >= 0xFFFFFFFFu;
CHECK(msgpack_array.errors == 1); CHECK(msgpack_array.errors == 1);
CHECK(msgpack_array.value == json::array()); CHECK(msgpack_array.value == (msgpack_array_fits ? json::array() : json(nullptr)));
const auto msgpack_map = parse_binary_recovering({0x81, 0xA1, 'a', 0x92, 0x01}, json::input_format_t::msgpack); const auto msgpack_map = parse_binary_recovering({0x81, 0xA1, 'a', 0x92, 0x01}, json::input_format_t::msgpack);
CHECK(msgpack_map.errors == 1); CHECK(msgpack_map.errors == 1);