mirror of
https://github.com/nlohmann/json.git
synced 2026-10-16 19:18:12 +00:00
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 <mail@nlohmann.me>
This commit is contained in:
2 files changed
+7
-6
No files matched your search
@@ -91,7 +91,7 @@ additionally linear in the combined length of the text and the decoded strings;
|
|||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
**The `image_check` modes.**
|
### `image_check` { #image_check }
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
using image_check = detail::view::image_check;
|
using image_check = detail::view::image_check;
|
||||||
|
|||||||
@@ -438,7 +438,7 @@ TEST_CASE("json_view images: errors")
|
|||||||
|
|
||||||
// the NULs after the text and the decoded strings
|
// the NULs after the text and the decoded strings
|
||||||
bad = image;
|
bad = image;
|
||||||
bad[text_at(image) + header_field(image, 16)] = 'x';
|
bad[text_at(image) + static_cast<std::size_t>(header_field(image, 16))] = 'x';
|
||||||
CHECK(load_result(bad, image_check::none) == prefix + "sizes out of range");
|
CHECK(load_result(bad, image_check::none) == prefix + "sizes out of range");
|
||||||
bad = image;
|
bad = image;
|
||||||
bad.back() = 'x';
|
bad.back() = 'x';
|
||||||
@@ -534,8 +534,8 @@ TEST_CASE("json_view images: check")
|
|||||||
|
|
||||||
SECTION("bounds")
|
SECTION("bounds")
|
||||||
{
|
{
|
||||||
const std::size_t text_size = header_field(image, 16);
|
const std::size_t text_size = static_cast<std::size_t>(header_field(image, 16));
|
||||||
const std::size_t arena_size = header_field(image, 24);
|
const std::size_t arena_size = static_cast<std::size_t>(header_field(image, 24));
|
||||||
rejected(corrupted(image, 1, [&](node & n)
|
rejected(corrupted(image, 1, [&](node & n)
|
||||||
{
|
{
|
||||||
n.off = static_cast<std::uint32_t>(text_size + 1);
|
n.off = static_cast<std::uint32_t>(text_size + 1);
|
||||||
@@ -624,7 +624,8 @@ TEST_CASE("json_view images: check")
|
|||||||
n.kind = 2; // {} as []: fine
|
n.kind = 2; // {} as []: fine
|
||||||
});
|
});
|
||||||
CHECK(load_result(as_array, image_check::full).empty());
|
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")
|
SECTION("strings")
|
||||||
@@ -641,7 +642,7 @@ TEST_CASE("json_view images: check")
|
|||||||
// invalid UTF-8 in a decoded string
|
// invalid UTF-8 in a decoded string
|
||||||
b = image;
|
b = image;
|
||||||
const node s2 = node_at(image, 2);
|
const node s2 = node_at(image, 2);
|
||||||
b[t + header_field(image, 16) + 1 + s2.off] = 0xFF;
|
b[t + static_cast<std::size_t>(header_field(image, 16)) + 1 + s2.off] = 0xFF;
|
||||||
rejected(b, false);
|
rejected(b, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user