mirror of
https://github.com/nlohmann/json.git
synced 2026-08-21 16:43:17 +00:00
Write a byte without walking a pointer over the buffer
clang-tidy's misc-const-correctness reads the pointer dump_byte advanced over the write buffer as one whose pointee could be const. Index the buffer instead, which says the same thing without a raw pointer at all. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -1384,21 +1384,21 @@ class serializer
|
||||
}
|
||||
|
||||
const auto byte = static_cast<unsigned>(value);
|
||||
char* out = write_buffer.data() + write_buffer_pos;
|
||||
std::size_t pos = write_buffer_pos;
|
||||
|
||||
if (byte >= 100)
|
||||
{
|
||||
*out++ = static_cast<char>('0' + (byte / 100));
|
||||
*out++ = static_cast<char>('0' + ((byte / 10) % 10));
|
||||
write_buffer[pos++] = static_cast<char>('0' + (byte / 100));
|
||||
write_buffer[pos++] = static_cast<char>('0' + ((byte / 10) % 10));
|
||||
}
|
||||
else if (byte >= 10)
|
||||
{
|
||||
*out++ = static_cast<char>('0' + (byte / 10));
|
||||
write_buffer[pos++] = static_cast<char>('0' + (byte / 10));
|
||||
}
|
||||
|
||||
*out++ = static_cast<char>('0' + (byte % 10));
|
||||
write_buffer[pos++] = static_cast<char>('0' + (byte % 10));
|
||||
|
||||
write_buffer_pos = static_cast<std::size_t>(out - write_buffer.data());
|
||||
write_buffer_pos = pos;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
Reference in New Issue
Block a user