From 29f7abf57d85547fecbc11b8cc8457a91d516fae Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Fri, 15 Jan 2021 17:01:47 +0100 Subject: [PATCH 1/3] :rotating_light: fix format-truncation warning #2572 --- include/nlohmann/detail/output/serializer.hpp | 4 ++-- single_include/nlohmann/json.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/nlohmann/detail/output/serializer.hpp b/include/nlohmann/detail/output/serializer.hpp index 0a34c8011..9e3f75660 100644 --- a/include/nlohmann/detail/output/serializer.hpp +++ b/include/nlohmann/detail/output/serializer.hpp @@ -497,7 +497,7 @@ class serializer { case error_handler_t::strict: { - std::string sn(3, '\0'); + std::string sn(8, '\0'); (std::snprintf)(&sn[0], sn.size(), "%.2X", byte); JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + sn)); } @@ -591,7 +591,7 @@ class serializer { case error_handler_t::strict: { - std::string sn(3, '\0'); + std::string sn(8, '\0'); (std::snprintf)(&sn[0], sn.size(), "%.2X", static_cast(s.back())); JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + sn)); } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 492118a5f..32865fd8e 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -16052,7 +16052,7 @@ class serializer { case error_handler_t::strict: { - std::string sn(3, '\0'); + std::string sn(8, '\0'); (std::snprintf)(&sn[0], sn.size(), "%.2X", byte); JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + sn)); } @@ -16146,7 +16146,7 @@ class serializer { case error_handler_t::strict: { - std::string sn(3, '\0'); + std::string sn(8, '\0'); (std::snprintf)(&sn[0], sn.size(), "%.2X", static_cast(s.back())); JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + sn)); } From 42218cac1b8d79af5117da6cf8b64b9afcffdc05 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 21 Jan 2021 22:01:09 +0100 Subject: [PATCH 2/3] :alembic: try 9 bytes --- include/nlohmann/detail/output/serializer.hpp | 4 ++-- single_include/nlohmann/json.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/nlohmann/detail/output/serializer.hpp b/include/nlohmann/detail/output/serializer.hpp index 9e3f75660..90bc65f93 100644 --- a/include/nlohmann/detail/output/serializer.hpp +++ b/include/nlohmann/detail/output/serializer.hpp @@ -497,7 +497,7 @@ class serializer { case error_handler_t::strict: { - std::string sn(8, '\0'); + std::string sn(9, '\0'); (std::snprintf)(&sn[0], sn.size(), "%.2X", byte); JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + sn)); } @@ -591,7 +591,7 @@ class serializer { case error_handler_t::strict: { - std::string sn(8, '\0'); + std::string sn(9, '\0'); (std::snprintf)(&sn[0], sn.size(), "%.2X", static_cast(s.back())); JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + sn)); } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 32865fd8e..768567567 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -16052,7 +16052,7 @@ class serializer { case error_handler_t::strict: { - std::string sn(8, '\0'); + std::string sn(9, '\0'); (std::snprintf)(&sn[0], sn.size(), "%.2X", byte); JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + sn)); } @@ -16146,7 +16146,7 @@ class serializer { case error_handler_t::strict: { - std::string sn(8, '\0'); + std::string sn(9, '\0'); (std::snprintf)(&sn[0], sn.size(), "%.2X", static_cast(s.back())); JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + sn)); } From 953dcfb61131452b36a8a59bf24102605037b0ca Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 15 Jul 2021 22:00:16 +0200 Subject: [PATCH 3/3] :rotating_light: fix warning #2572 --- single_include/nlohmann/json.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 429964dd7..c0de5acac 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -16459,7 +16459,7 @@ class serializer { case error_handler_t::strict: { - std::string sn(3, '\0'); + std::string sn(9, '\0'); // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg) (std::snprintf)(&sn[0], sn.size(), "%.2X", byte); JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + sn, BasicJsonType())); @@ -16554,7 +16554,7 @@ class serializer { case error_handler_t::strict: { - std::string sn(3, '\0'); + std::string sn(9, '\0'); // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg) (std::snprintf)(&sn[0], sn.size(), "%.2X", static_cast(s.back())); JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + sn, BasicJsonType()));