Unverified Commit c89e23c6 authored by Niels Lohmann's avatar Niels Lohmann Committed by GitHub

Merge pull request #2874 from nlohmann/issue2572

Fix truncation warning
parents f883ddd1 953dcfb6
......@@ -499,7 +499,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()));
......@@ -594,7 +594,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<std::uint8_t>(s.back()));
JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + sn, BasicJsonType()));
......
......@@ -16484,7 +16484,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()));
......@@ -16579,7 +16579,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<std::uint8_t>(s.back()));
JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + sn, BasicJsonType()));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment