From 598fbd0417170e4e325557e4001c0100ac778c68 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 14 Oct 2026 21:30:07 +0200 Subject: [PATCH] Avoid implicit unsigned char to char conversion in stream tests Building a std::string from the iterators of a CBOR byte vector narrows each byte, which -fsanitize=implicit-conversion reports for bytes above 0x7F. Construct the string from the raw bytes instead. Signed-off-by: Niels Lohmann --- tests/src/unit-file_input.cpp | 2 +- tests/src/unit-stream-bulk-scan.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/src/unit-file_input.cpp b/tests/src/unit-file_input.cpp index eaa378aa8..c3e587e74 100644 --- a/tests/src/unit-file_input.cpp +++ b/tests/src/unit-file_input.cpp @@ -226,7 +226,7 @@ TEST_CASE("parsing from a FILE*") { const json j = {{"string", std::string(300, 'x')}, {"array", {1, 2, 3}}, {"number", 1.5}}; const std::vector cbor = json::to_cbor(j); - const file_ptr f = open_with(name, std::string(cbor.begin(), cbor.end())); + const file_ptr f = open_with(name, std::string(reinterpret_cast(cbor.data()), cbor.size())); REQUIRE(f != nullptr); CHECK(json::from_cbor(f.get()) == j); check_unlocked(f.get()); diff --git a/tests/src/unit-stream-bulk-scan.cpp b/tests/src/unit-stream-bulk-scan.cpp index f46c4351f..b5b6ded15 100644 --- a/tests/src/unit-stream-bulk-scan.cpp +++ b/tests/src/unit-stream-bulk-scan.cpp @@ -371,7 +371,7 @@ TEST_CASE("parsing from a std::istream scans the get area in bulk") { const json j = {{"string", std::string(300, 'x')}, {"array", {1, 2, 3}}, {"number", 1.5}}; const std::vector cbor = json::to_cbor(j); - const std::string bytes(cbor.begin(), cbor.end()); + const std::string bytes(reinterpret_cast(cbor.data()), cbor.size()); for (const std::size_t chunk_size : chunk_sizes()) { CAPTURE(chunk_size)