🚨 fix warning (#5169)

This commit is contained in:
Niels Lohmann
2026-05-14 15:39:18 +02:00
committed by GitHub
parent 85cb7ea9aa
commit 5a05627b1f
5 changed files with 36 additions and 10 deletions

View File

@@ -825,14 +825,27 @@ class serializer
o->write_characters(begin, static_cast<size_t>(end - begin));
}
JSON_HEDLEY_NON_NULL(1)
static int snprintf_float(char* buf, std::size_t size, int d, double x)
{
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
return (std::snprintf)(buf, size, "%.*g", d, x);
}
JSON_HEDLEY_NON_NULL(1)
static int snprintf_float(char* buf, std::size_t size, int d, long double x)
{
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
return (std::snprintf)(buf, size, "%.*lg", d, x);
}
void dump_float(number_float_t x, std::false_type /*is_ieee_single_or_double*/)
{
// get the number of digits for a float -> text -> float round-trip
static constexpr auto d = std::numeric_limits<number_float_t>::max_digits10;
// the actual conversion
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(), "%.*g", d, x);
std::ptrdiff_t len = snprintf_float(number_buffer.data(), number_buffer.size(), d, x);
// negative value indicates an error
JSON_ASSERT(len > 0);