From eb7bd2dbc9e684b47d7d9335c0393a74a9ad024e Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 22 Oct 2026 16:07:11 +0200 Subject: [PATCH] Compare the bytes of the binary writer sink tests without converting each one std::string(begin, end) over a std::vector converts every byte to char, which Clang's -fsanitize=integer reports for bytes above 0x7F where char is signed (x86-64 with libstdc++). The string is now made from the vector's data. Signed-off-by: Niels Lohmann --- tests/src/unit-binary_writer_sinks.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/src/unit-binary_writer_sinks.cpp b/tests/src/unit-binary_writer_sinks.cpp index a7844e9c3..b880a16e2 100644 --- a/tests/src/unit-binary_writer_sinks.cpp +++ b/tests/src/unit-binary_writer_sinks.cpp @@ -720,7 +720,7 @@ TEST_CASE("a write that throws leaves the same bytes in every kind of output") CHECK_THROWS_AS(json::to_cbor(document, as_string, strict), json::type_error&); CHECK_THROWS_AS(json::to_cbor(document, as_stream, strict), json::type_error&); CHECK(!as_vector.empty()); - CHECK(std::string(as_vector.begin(), as_vector.end()) == as_string); + CHECK(std::string(reinterpret_cast(as_vector.data()), as_vector.size()) == as_string); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast) CHECK(as_stream.str() == as_string); } @@ -733,7 +733,7 @@ TEST_CASE("a write that throws leaves the same bytes in every kind of output") CHECK_THROWS_AS(json::to_msgpack(document, as_string, strict), json::type_error&); CHECK_THROWS_AS(json::to_msgpack(document, as_stream, strict), json::type_error&); CHECK(!as_vector.empty()); - CHECK(std::string(as_vector.begin(), as_vector.end()) == as_string); + CHECK(std::string(reinterpret_cast(as_vector.data()), as_vector.size()) == as_string); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast) CHECK(as_stream.str() == as_string); } @@ -746,7 +746,7 @@ TEST_CASE("a write that throws leaves the same bytes in every kind of output") CHECK_THROWS_AS(json::to_ubjson(document, as_string, false, false, strict), json::type_error&); CHECK_THROWS_AS(json::to_ubjson(document, as_stream, false, false, strict), json::type_error&); CHECK(!as_vector.empty()); - CHECK(std::string(as_vector.begin(), as_vector.end()) == as_string); + CHECK(std::string(reinterpret_cast(as_vector.data()), as_vector.size()) == as_string); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast) CHECK(as_stream.str() == as_string); }