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 <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann committed 2026-10-14 21:30:07 +02:00
1 parent 898084b386
commit 598fbd0417
2 files changed
+2 -2

No files matched your search

+1 -1
View File
@@ -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<std::uint8_t> 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<const char*>(cbor.data()), cbor.size()));
REQUIRE(f != nullptr);
CHECK(json::from_cbor(f.get()) == j);
check_unlocked(f.get());
+1 -1
View File
@@ -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<std::uint8_t> cbor = json::to_cbor(j);
const std::string bytes(cbor.begin(), cbor.end());
const std::string bytes(reinterpret_cast<const char*>(cbor.data()), cbor.size());
for (const std::size_t chunk_size : chunk_sizes())
{
CAPTURE(chunk_size)