From 1c588321c5bc08ae87fff093a9b713993cf2e406 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 31 Oct 2026 07:28:43 +0000 Subject: [PATCH] Fix UBSan implicit-conversion in BSON stream tests std::string(first, last) over std::uint8_t iterators converts each byte to char implicitly, which -fsanitize=implicit-conversion reports as soon as a byte is >= 0x80 (the document size byte of the enlarged test input, and 0xFF in the new array element name test). Build the string from a const char* and a size instead. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01N5NasCxh8jKXBaa6HBx9Xk Signed-off-by: Niels Lohmann --- tests/src/unit-bson.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/src/unit-bson.cpp b/tests/src/unit-bson.cpp index 46e9ae457..f93e0a71b 100644 --- a/tests/src/unit-bson.cpp +++ b/tests/src/unit-bson.cpp @@ -1190,7 +1190,7 @@ TEST_CASE("BSON keys from contiguous and stream input") } try { - std::istringstream stream(std::string(input.begin(), input.end())); + std::istringstream stream(std::string(reinterpret_cast(input.data()), input.size())); from_stream = json::from_bson(stream).dump(); } catch (const json::parse_error& e) @@ -1224,7 +1224,7 @@ TEST_CASE("BSON array element names") json _; CHECK_THROWS_WITH_AS(_ = json::from_bson(bson, true, true, json::error_handler_t::strict), "[json.exception.parse_error.113] parse error at byte 14: syntax error while parsing BSON key: invalid string: ill-formed UTF-8 byte", json::parse_error&); - std::istringstream stream(std::string(bson.begin(), bson.end())); + std::istringstream stream(std::string(reinterpret_cast(bson.data()), bson.size())); CHECK(json::from_bson(stream) == expected); } #endif