From e32337d5a8498a6a3b098d157560878c590ecb90 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 20 Aug 2026 21:53:28 +0200 Subject: [PATCH] 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 --- include/nlohmann/detail/output/serializer.hpp | 12 ++++++------ single_include/nlohmann/json.hpp | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/nlohmann/detail/output/serializer.hpp b/include/nlohmann/detail/output/serializer.hpp index 312d2e388..20a65d76e 100644 --- a/include/nlohmann/detail/output/serializer.hpp +++ b/include/nlohmann/detail/output/serializer.hpp @@ -1384,21 +1384,21 @@ class serializer } const auto byte = static_cast(value); - char* out = write_buffer.data() + write_buffer_pos; + std::size_t pos = write_buffer_pos; if (byte >= 100) { - *out++ = static_cast('0' + (byte / 100)); - *out++ = static_cast('0' + ((byte / 10) % 10)); + write_buffer[pos++] = static_cast('0' + (byte / 100)); + write_buffer[pos++] = static_cast('0' + ((byte / 10) % 10)); } else if (byte >= 10) { - *out++ = static_cast('0' + (byte / 10)); + write_buffer[pos++] = static_cast('0' + (byte / 10)); } - *out++ = static_cast('0' + (byte % 10)); + write_buffer[pos++] = static_cast('0' + (byte % 10)); - write_buffer_pos = static_cast(out - write_buffer.data()); + write_buffer_pos = pos; } /*! diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index b304baab3..567bd68ba 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -22317,21 +22317,21 @@ class serializer } const auto byte = static_cast(value); - char* out = write_buffer.data() + write_buffer_pos; + std::size_t pos = write_buffer_pos; if (byte >= 100) { - *out++ = static_cast('0' + (byte / 100)); - *out++ = static_cast('0' + ((byte / 10) % 10)); + write_buffer[pos++] = static_cast('0' + (byte / 100)); + write_buffer[pos++] = static_cast('0' + ((byte / 10) % 10)); } else if (byte >= 10) { - *out++ = static_cast('0' + (byte / 10)); + write_buffer[pos++] = static_cast('0' + (byte / 10)); } - *out++ = static_cast('0' + (byte % 10)); + write_buffer[pos++] = static_cast('0' + (byte % 10)); - write_buffer_pos = static_cast(out - write_buffer.data()); + write_buffer_pos = pos; } /*!