From 394bef9090c972a00d8bae63e85e74d837e6961f 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 6d4617d1c..f6a3cc879 100644 --- a/include/nlohmann/detail/output/serializer.hpp +++ b/include/nlohmann/detail/output/serializer.hpp @@ -1383,21 +1383,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 36cd83bb5..90890fff6 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -22737,21 +22737,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; } /*!