From 0a8216890d51f0d06eb0382eabc35ceb7053daf7 Mon Sep 17 00:00:00 2001 From: chenguoping Date: Mon, 23 Mar 2020 15:27:35 +0800 Subject: [PATCH] fix C26451 warnnings in to_chars.hpp --- include/nlohmann/detail/conversions/to_chars.hpp | 16 ++++++++-------- single_include/nlohmann/json.hpp | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/include/nlohmann/detail/conversions/to_chars.hpp b/include/nlohmann/detail/conversions/to_chars.hpp index d99703a5..a7856253 100644 --- a/include/nlohmann/detail/conversions/to_chars.hpp +++ b/include/nlohmann/detail/conversions/to_chars.hpp @@ -990,11 +990,11 @@ 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'; - return buf + (n + 2); + return buf + (static_cast(n) + 2); } if (0 < n and n <= max_exp) @@ -1004,9 +1004,9 @@ 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 + (static_cast(n) + 1), buf + n, static_cast(k) - static_cast(n)); buf[n] = '.'; - return buf + (k + 1); + return buf + (static_cast(k) + 1); } if (min_exp < n and n <= 0) @@ -1014,11 +1014,11 @@ inline char* format_buffer(char* buf, int len, int decimal_exponent, // 0.[000]digits // len <= 2 + (-min_exp - 1) + max_digits10 - std::memmove(buf + (2 + -n), buf, static_cast(k)); + std::memmove(buf + (2 + static_cast(-n)), buf, static_cast(k)); buf[0] = '0'; buf[1] = '.'; std::memset(buf + 2, '0', static_cast(-n)); - return buf + (2 + (-n) + k); + return buf + (2 + static_cast(-n) + k); } if (k == 1) @@ -1033,9 +1033,9 @@ inline char* format_buffer(char* buf, int len, int decimal_exponent, // d.igitsE+123 // len <= max_digits10 + 1 + 5 - std::memmove(buf + 2, buf + 1, static_cast(k - 1)); + std::memmove(buf + 2, buf + 1, static_cast(k) - 1); buf[1] = '.'; - buf += 1 + k; + buf += 1 + static_cast(k); } *buf++ = 'e'; diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 68916fa0..fd2e6a86 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -13639,11 +13639,11 @@ 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'; - return buf + (n + 2); + return buf + (static_cast(n) + 2); } if (0 < n and n <= max_exp) @@ -13653,9 +13653,9 @@ 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 + (static_cast(n) + 1), buf + n, static_cast(k) - static_cast(n)); buf[n] = '.'; - return buf + (k + 1); + return buf + (static_cast(k) + 1); } if (min_exp < n and n <= 0) @@ -13663,11 +13663,11 @@ inline char* format_buffer(char* buf, int len, int decimal_exponent, // 0.[000]digits // len <= 2 + (-min_exp - 1) + max_digits10 - std::memmove(buf + (2 + -n), buf, static_cast(k)); + std::memmove(buf + (2 + static_cast(-n)), buf, static_cast(k)); buf[0] = '0'; buf[1] = '.'; std::memset(buf + 2, '0', static_cast(-n)); - return buf + (2 + (-n) + k); + return buf + (2 + static_cast(-n) + k); } if (k == 1) @@ -13682,9 +13682,9 @@ inline char* format_buffer(char* buf, int len, int decimal_exponent, // d.igitsE+123 // len <= max_digits10 + 1 + 5 - std::memmove(buf + 2, buf + 1, static_cast(k - 1)); + std::memmove(buf + 2, buf + 1, static_cast(k) - 1); buf[1] = '.'; - buf += 1 + k; + buf += 1 + static_cast(k); } *buf++ = 'e';