From 818ec541d93cd98ac756f7ed513695c3199e1fe6 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 8 Oct 2026 16:22:58 +0200 Subject: [PATCH] Fix MSVC errors in image test and add image_check doc anchor Move the raw string literal out of the CHECK macro (MSVC preprocessor), cast 64-bit header fields to std::size_t (C4244 on 32-bit), and give the image_check section in load.md a real anchor for the mkdocs strict build. Signed-off-by: Niels Lohmann --- docs/mkdocs/docs/api/basic_json_document/load.md | 2 +- tests/src/unit-json_view_image.cpp | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/mkdocs/docs/api/basic_json_document/load.md b/docs/mkdocs/docs/api/basic_json_document/load.md index 43cc60aa3..7369ff11a 100644 --- a/docs/mkdocs/docs/api/basic_json_document/load.md +++ b/docs/mkdocs/docs/api/basic_json_document/load.md @@ -91,7 +91,7 @@ additionally linear in the combined length of the text and the decoded strings; ## Notes -**The `image_check` modes.** +### `image_check` { #image_check } ```cpp using image_check = detail::view::image_check; diff --git a/tests/src/unit-json_view_image.cpp b/tests/src/unit-json_view_image.cpp index d520cd5d1..6a615f7d4 100644 --- a/tests/src/unit-json_view_image.cpp +++ b/tests/src/unit-json_view_image.cpp @@ -438,7 +438,7 @@ TEST_CASE("json_view images: errors") // the NULs after the text and the decoded strings bad = image; - bad[text_at(image) + header_field(image, 16)] = 'x'; + bad[text_at(image) + static_cast(header_field(image, 16))] = 'x'; CHECK(load_result(bad, image_check::none) == prefix + "sizes out of range"); bad = image; bad.back() = 'x'; @@ -534,8 +534,8 @@ TEST_CASE("json_view images: check") SECTION("bounds") { - const std::size_t text_size = header_field(image, 16); - const std::size_t arena_size = header_field(image, 24); + const std::size_t text_size = static_cast(header_field(image, 16)); + const std::size_t arena_size = static_cast(header_field(image, 24)); rejected(corrupted(image, 1, [&](node & n) { n.off = static_cast(text_size + 1); @@ -624,7 +624,8 @@ TEST_CASE("json_view images: check") n.kind = 2; // {} as []: fine }); CHECK(load_result(as_array, image_check::full).empty()); - CHECK(json_document::load(as_array).root().dump() == R"({"s":"x\"y","i":-12,"u":7,"f":1.5e+300,"b":true,"n":null,"a":["t",[]]})"); + const std::string expected_dump = R"({"s":"x\"y","i":-12,"u":7,"f":1.5e+300,"b":true,"n":null,"a":["t",[]]})"; + CHECK(json_document::load(as_array).root().dump() == expected_dump); } SECTION("strings") @@ -641,7 +642,7 @@ TEST_CASE("json_view images: check") // invalid UTF-8 in a decoded string b = image; const node s2 = node_at(image, 2); - b[t + header_field(image, 16) + 1 + s2.off] = 0xFF; + b[t + static_cast(header_field(image, 16)) + 1 + s2.off] = 0xFF; rejected(b, false); }