mirror of
https://github.com/nlohmann/json.git
synced 2026-11-21 18:32:40 +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:
1 file changed
+9
-1
@@ -105,7 +105,15 @@ using bytes = std::vector<std::uint8_t>;
|
|||||||
/// @return the string with the given bytes
|
/// @return the string with the given bytes
|
||||||
std::string str(const bytes& b)
|
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
|
/// 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