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:
Niels Lohmann
2026-08-21 04:51:22 +02:00
parent aa80ade75b
commit e32337d5a8
2 changed files with 12 additions and 12 deletions
@@ -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;
}
/*!
+6 -6
View File
@@ -22317,21 +22317,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;
}
/*!