Skip to content

Commit

Permalink
Merge pull request #2874 from nlohmann/issue2572
Browse files Browse the repository at this point in the history
Fix truncation warning
  • Loading branch information
nlohmann authored Jul 16, 2021
2 parents f883ddd + 953dcfb commit c89e23c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions include/nlohmann/detail/output/serializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down Expand Up @@ -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()));
Expand Down
4 changes: 2 additions & 2 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down Expand Up @@ -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()));
Expand Down

0 comments on commit c89e23c

Please sign in to comment.