From 4fb0795ec1072c9fc582020d1cd79850731bffec Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 19 Apr 2020 13:01:36 +0200 Subject: [PATCH] :rotating_light: fix compiler warnings #2049 --- include/nlohmann/detail/conversions/to_chars.hpp | 4 ++-- include/nlohmann/detail/output/serializer.hpp | 3 +-- single_include/nlohmann/json.hpp | 7 +++---- test/src/unit-deserialization.cpp | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/include/nlohmann/detail/conversions/to_chars.hpp b/include/nlohmann/detail/conversions/to_chars.hpp index a7856253..aed587cc 100644 --- a/include/nlohmann/detail/conversions/to_chars.hpp +++ b/include/nlohmann/detail/conversions/to_chars.hpp @@ -1006,7 +1006,7 @@ inline char* format_buffer(char* buf, int len, int decimal_exponent, std::memmove(buf + (static_cast(n) + 1), buf + n, static_cast(k) - static_cast(n)); buf[n] = '.'; - return buf + (static_cast(k) + 1); + return buf + (static_cast(k) + 1U); } if (min_exp < n and n <= 0) @@ -1018,7 +1018,7 @@ inline char* format_buffer(char* buf, int len, int decimal_exponent, buf[0] = '0'; buf[1] = '.'; std::memset(buf + 2, '0', static_cast(-n)); - return buf + (2 + static_cast(-n) + k); + return buf + (2U + static_cast(-n) + static_cast(k)); } if (k == 1) diff --git a/include/nlohmann/detail/output/serializer.hpp b/include/nlohmann/detail/output/serializer.hpp index d598ffe2..e8ae8a09 100644 --- a/include/nlohmann/detail/output/serializer.hpp +++ b/include/nlohmann/detail/output/serializer.hpp @@ -259,8 +259,7 @@ class serializer { dump_integer(*i); o->write_character(','); - int index = i - val.m_value.binary->cbegin(); - if (index % 16 == 0) + if (std::distance(val.m_value.binary->cbegin(), i) % 16 == 0) { o->write_character('\n'); } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 1b7190a1..a51bff87 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -14543,7 +14543,7 @@ inline char* format_buffer(char* buf, int len, int decimal_exponent, std::memmove(buf + (static_cast(n) + 1), buf + n, static_cast(k) - static_cast(n)); buf[n] = '.'; - return buf + (static_cast(k) + 1); + return buf + (static_cast(k) + 1U); } if (min_exp < n and n <= 0) @@ -14555,7 +14555,7 @@ inline char* format_buffer(char* buf, int len, int decimal_exponent, buf[0] = '0'; buf[1] = '.'; std::memset(buf + 2, '0', static_cast(-n)); - return buf + (2 + static_cast(-n) + k); + return buf + (2U + static_cast(-n) + static_cast(k)); } if (k == 1) @@ -14892,8 +14892,7 @@ class serializer { dump_integer(*i); o->write_character(','); - int index = i - val.m_value.binary->cbegin(); - if (index % 16 == 0) + if (std::distance(val.m_value.binary->cbegin(), i) % 16 == 0) { o->write_character('\n'); } diff --git a/test/src/unit-deserialization.cpp b/test/src/unit-deserialization.cpp index 7f2a0d38..a8688715 100644 --- a/test/src/unit-deserialization.cpp +++ b/test/src/unit-deserialization.cpp @@ -76,7 +76,7 @@ struct SaxEventLogger : public nlohmann::json_sax return true; } - bool binary(std::vector& val) + bool binary(std::vector& val) override { std::string binary_contents = "binary("; std::string comma_space = "";