Convert the bytes of the BON8 test strings explicitly

The str() helper constructed a std::string from a byte range, which
converts each unsigned char implicitly; -fsanitize=integer reports that
for bytes of 0x80 and above (ci_test_clang_sanitizer).

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann
2026-09-27 08:06:15 +02:00
parent 4adf70fe81
commit d7ea86d225
+9 -1
View File
@@ -105,7 +105,15 @@ using bytes = std::vector<std::uint8_t>;
/// @return the string with the given bytes
std::string str(const bytes& b)
{
return {b.begin(), b.end()};
// converted one by one: constructing the string from the byte range
// converts implicitly, which -fsanitize=integer reports for bytes >= 0x80
std::string result;
result.reserve(b.size());
for (const auto c : b)
{
result.push_back(static_cast<char>(c));
}
return result;
}
/// check that @a j is serialized to @a expected and that @a expected is read back as @a j