diff --git a/include/nlohmann/detail/conversions/to_chars.hpp b/include/nlohmann/detail/conversions/to_chars.hpp index d99703a54..47951d2ea 100644 --- a/include/nlohmann/detail/conversions/to_chars.hpp +++ b/include/nlohmann/detail/conversions/to_chars.hpp @@ -990,7 +990,7 @@ inline char* format_buffer(char* buf, int len, int decimal_exponent, // digits[000] // len <= max_exp + 2 - std::memset(buf + k, '0', static_cast(n - k)); + std::memset(buf + k, '0', static_cast(n) - static_cast(k)); // Make it look like a floating-point number (#362, #378) buf[n + 0] = '.'; buf[n + 1] = '0'; @@ -1004,7 +1004,7 @@ inline char* format_buffer(char* buf, int len, int decimal_exponent, assert(k > n); - std::memmove(buf + (n + 1), buf + n, static_cast(k - n)); + std::memmove(buf + (n + 1), buf + n, static_cast(k) - static_cast(n)); buf[n] = '.'; return buf + (k + 1); } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index de146ed61..5aaf11ccb 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -13955,7 +13955,7 @@ inline char* format_buffer(char* buf, int len, int decimal_exponent, // digits[000] // len <= max_exp + 2 - std::memset(buf + k, '0', static_cast(n - k)); + std::memset(buf + k, '0', static_cast(n) - static_cast(k)); // Make it look like a floating-point number (#362, #378) buf[n + 0] = '.'; buf[n + 1] = '0'; @@ -13969,7 +13969,7 @@ inline char* format_buffer(char* buf, int len, int decimal_exponent, assert(k > n); - std::memmove(buf + (n + 1), buf + n, static_cast(k - n)); + std::memmove(buf + (n + 1), buf + n, static_cast(k) - static_cast(n)); buf[n] = '.'; return buf + (k + 1); }