From a9ed3feca3b4ea63e34f9ba0fd1282fa47364c1a Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 22 Oct 2026 13:32:19 +0200 Subject: [PATCH] Copy the tokens of json_pointer::to_string() with std::copy clang-tidy (bugprone-not-null-terminated-result) took the memcpy into the result string for a C string missing its terminator. std::copy is the same memmove; to_string() instructions are unchanged (Apple clang). Signed-off-by: Niels Lohmann --- include/nlohmann/detail/json_pointer.hpp | 5 ++--- single_include/nlohmann/json.hpp | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/include/nlohmann/detail/json_pointer.hpp b/include/nlohmann/detail/json_pointer.hpp index ce7fd267a..8e9a74fb3 100644 --- a/include/nlohmann/detail/json_pointer.hpp +++ b/include/nlohmann/detail/json_pointer.hpp @@ -8,7 +8,7 @@ #pragma once -#include // all_of +#include // all_of, copy #include // array #include // isdigit #include // errno, ERANGE @@ -104,8 +104,7 @@ class json_pointer for (const auto& reference_token : reference_tokens) { *out++ = '/'; - std::memcpy(out, reference_token.data(), reference_token.size()); - out += reference_token.size(); + out = std::copy(reference_token.data(), reference_token.data() + reference_token.size(), out); } } return result; diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index cfb263e83..cd5f87737 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -22350,7 +22350,7 @@ NLOHMANN_JSON_NAMESPACE_END -#include // all_of +#include // all_of, copy #include // array #include // isdigit #include // errno, ERANGE @@ -22454,8 +22454,7 @@ class json_pointer for (const auto& reference_token : reference_tokens) { *out++ = '/'; - std::memcpy(out, reference_token.data(), reference_token.size()); - out += reference_token.size(); + out = std::copy(reference_token.data(), reference_token.data() + reference_token.size(), out); } } return result;