mirror of
https://github.com/nlohmann/json.git
synced 2026-09-28 02:30:32 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user