Use std::array for the index buffer in append_index()

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann committed 2026-10-20 07:47:38 +02:00
1 parent 7c5f93cc91
commit 1fb725a488
2 files changed
+8 -6

No files matched your search

+4 -3
View File
@@ -9,6 +9,7 @@
#pragma once #pragma once
#include <algorithm> // all_of #include <algorithm> // all_of
#include <array> // array
#include <cctype> // isdigit #include <cctype> // isdigit
#include <cerrno> // errno, ERANGE #include <cerrno> // errno, ERANGE
#include <cstddef> // size_t #include <cstddef> // size_t
@@ -1270,15 +1271,15 @@ class json_pointer
/// append the decimal representation of @a i to @a out /// append the decimal representation of @a i to @a out
static void append_index(string_t& out, std::size_t i) static void append_index(string_t& out, std::size_t i)
{ {
char buf[24]; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) std::array<char, 24> buf{};
std::size_t pos = sizeof(buf); std::size_t pos = buf.size();
do do
{ {
buf[--pos] = static_cast<char>('0' + i % 10); buf[--pos] = static_cast<char>('0' + i % 10);
i /= 10; i /= 10;
} }
while (i != 0); while (i != 0);
out.append(buf + pos, sizeof(buf) - pos); out.append(buf.data() + pos, buf.size() - pos);
} }
/*! /*!
+4 -3
View File
@@ -21427,6 +21427,7 @@ NLOHMANN_JSON_NAMESPACE_END
#include <algorithm> // all_of #include <algorithm> // all_of
#include <array> // array
#include <cctype> // isdigit #include <cctype> // isdigit
#include <cerrno> // errno, ERANGE #include <cerrno> // errno, ERANGE
#include <cstddef> // size_t #include <cstddef> // size_t
@@ -22695,15 +22696,15 @@ class json_pointer
/// append the decimal representation of @a i to @a out /// append the decimal representation of @a i to @a out
static void append_index(string_t& out, std::size_t i) static void append_index(string_t& out, std::size_t i)
{ {
char buf[24]; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) std::array<char, 24> buf{};
std::size_t pos = sizeof(buf); std::size_t pos = buf.size();
do do
{ {
buf[--pos] = static_cast<char>('0' + i % 10); buf[--pos] = static_cast<char>('0' + i % 10);
i /= 10; i /= 10;
} }
while (i != 0); while (i != 0);
out.append(buf + pos, sizeof(buf) - pos); out.append(buf.data() + pos, buf.size() - pos);
} }
/*! /*!