diff --git a/cmake/requirements/requirements-cppcheck.txt b/cmake/requirements/requirements-cppcheck.txt index 9119ad7b6..aa1591128 100644 --- a/cmake/requirements/requirements-cppcheck.txt +++ b/cmake/requirements/requirements-cppcheck.txt @@ -1 +1 @@ -cppcheck==1.5.0 +cppcheck==1.5.1 diff --git a/include/nlohmann/detail/output/serializer.hpp b/include/nlohmann/detail/output/serializer.hpp index fc078532c..d3d81bfd2 100644 --- a/include/nlohmann/detail/output/serializer.hpp +++ b/include/nlohmann/detail/output/serializer.hpp @@ -830,9 +830,11 @@ class serializer // get number of digits for a float -> text -> float round-trip static constexpr auto d = std::numeric_limits::max_digits10; - // the actual conversion + // the actual conversion (Note that is_ieee_single_or_double==false + // rules out that number_float_t is double or long double. Therefore, + // we need to cast the argument x to double to be able to use snprintf.) // 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 = (std::snprintf)(number_buffer.data(), number_buffer.size(), "%.*g", d, static_cast(x)); // negative value indicates an error JSON_ASSERT(len > 0); diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 93e5983cf..391d54cd4 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -19565,9 +19565,11 @@ class serializer // get number of digits for a float -> text -> float round-trip static constexpr auto d = std::numeric_limits::max_digits10; - // the actual conversion + // the actual conversion (Note that is_ieee_single_or_double==false + // rules out that number_float_t is double or long double. Therefore, + // we need to cast the argument x to double to be able to use snprintf.) // 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 = (std::snprintf)(number_buffer.data(), number_buffer.size(), "%.*g", d, static_cast(x)); // negative value indicates an error JSON_ASSERT(len > 0);