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)); }