From 719dfa41fb9b65b068c4fa0f0d8dcbbb43c36afc Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 17 Oct 2026 07:26:31 +0200 Subject: [PATCH] Convert the streamed bytes explicitly in the binary writer sink tests Signed-off-by: Niels Lohmann --- tests/src/unit-binary_writer_sinks.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/src/unit-binary_writer_sinks.cpp b/tests/src/unit-binary_writer_sinks.cpp index db1e18537..b894d3f7f 100644 --- a/tests/src/unit-binary_writer_sinks.cpp +++ b/tests/src/unit-binary_writer_sinks.cpp @@ -64,6 +64,18 @@ std::vector test_values() }; } +// explicit char -> uint8_t conversion (the iterator-range constructor converts implicitly, which -fsanitize=integer flags) +std::vector to_bytes(const std::string& str) +{ + std::vector result; + result.reserve(str.size()); + for (const char c : str) + { + result.push_back(static_cast(c)); + } + return result; +} + // BON8 has no integers above the int64 range, so to_bon8() rejects them bool bon8_representable(const json& j) { @@ -407,11 +419,11 @@ TEST_CASE("CBOR and MessagePack integer arrays") std::ostringstream stream; json::to_cbor(array, stream); std::string streamed = stream.str(); - CHECK(std::vector(streamed.begin(), streamed.end()) == expected_cbor); + CHECK(to_bytes(streamed) == expected_cbor); stream.str(""); json::to_msgpack(array, stream); streamed = stream.str(); - CHECK(std::vector(streamed.begin(), streamed.end()) == expected_msgpack); + CHECK(to_bytes(streamed) == expected_msgpack); CHECK(json::from_cbor(expected_cbor) == array); CHECK(json::from_msgpack(expected_msgpack) == array);