diff --git a/include/nlohmann/detail/input/binary_reader.hpp b/include/nlohmann/detail/input/binary_reader.hpp index 6f91f0df..5f3efaaf 100644 --- a/include/nlohmann/detail/input/binary_reader.hpp +++ b/include/nlohmann/detail/input/binary_reader.hpp @@ -264,7 +264,7 @@ class binary_reader default: // anything else not supported (yet) { char cr[3]; - snprintf(cr, sizeof(cr), "%.2hhX", static_cast(element_type)); + (std::snprintf)(cr, sizeof(cr), "%.2hhX", static_cast(element_type)); return sax->parse_error(element_type_parse_position, std::string(cr), parse_error::create(114, element_type_parse_position, "Unsupported BSON record type 0x" + std::string(cr))); } } @@ -1921,7 +1921,7 @@ class binary_reader std::string get_token_string() const { char cr[3]; - snprintf(cr, 3, "%.2hhX", static_cast(current)); + (std::snprintf)(cr, 3, "%.2hhX", static_cast(current)); return std::string{cr}; } diff --git a/include/nlohmann/detail/input/lexer.hpp b/include/nlohmann/detail/input/lexer.hpp index dd474525..c3ecbee9 100644 --- a/include/nlohmann/detail/input/lexer.hpp +++ b/include/nlohmann/detail/input/lexer.hpp @@ -1360,7 +1360,7 @@ scan_number_done: { // escape control characters char cs[9]; - snprintf(cs, 9, "", static_cast(c)); + (std::snprintf)(cs, 9, "", static_cast(c)); result += cs; } else diff --git a/include/nlohmann/detail/output/serializer.hpp b/include/nlohmann/detail/output/serializer.hpp index a709a8ec..da5199b8 100644 --- a/include/nlohmann/detail/output/serializer.hpp +++ b/include/nlohmann/detail/output/serializer.hpp @@ -372,15 +372,15 @@ class serializer { if (codepoint <= 0xFFFF) { - std::snprintf(string_buffer.data() + bytes, 7, "\\u%04x", - static_cast(codepoint)); + (std::snprintf)(string_buffer.data() + bytes, 7, "\\u%04x", + static_cast(codepoint)); bytes += 6; } else { - std::snprintf(string_buffer.data() + bytes, 13, "\\u%04x\\u%04x", - static_cast(0xD7C0 + (codepoint >> 10)), - static_cast(0xDC00 + (codepoint & 0x3FF))); + (std::snprintf)(string_buffer.data() + bytes, 13, "\\u%04x\\u%04x", + static_cast(0xD7C0 + (codepoint >> 10)), + static_cast(0xDC00 + (codepoint & 0x3FF))); bytes += 12; } } @@ -416,7 +416,7 @@ class serializer case error_handler_t::strict: { std::string sn(3, '\0'); - snprintf(&sn[0], sn.size(), "%.2X", byte); + (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)); } @@ -497,7 +497,7 @@ class serializer case error_handler_t::strict: { std::string sn(3, '\0'); - snprintf(&sn[0], sn.size(), "%.2X", static_cast(s.back())); + (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)); } @@ -616,7 +616,7 @@ class serializer static constexpr auto d = std::numeric_limits::max_digits10; // the actual conversion - std::ptrdiff_t len = snprintf(number_buffer.data(), number_buffer.size(), "%.*g", d, x); + std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(), "%.*g", d, x); // negative value indicates an error assert(len > 0); diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 19fb6ddf..7c31d212 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -3812,7 +3812,7 @@ scan_number_done: { // escape control characters char cs[9]; - snprintf(cs, 9, "", static_cast(c)); + (std::snprintf)(cs, 9, "", static_cast(c)); result += cs; } else @@ -6605,7 +6605,7 @@ class binary_reader default: // anything else not supported (yet) { char cr[3]; - snprintf(cr, sizeof(cr), "%.2hhX", static_cast(element_type)); + (std::snprintf)(cr, sizeof(cr), "%.2hhX", static_cast(element_type)); return sax->parse_error(element_type_parse_position, std::string(cr), parse_error::create(114, element_type_parse_position, "Unsupported BSON record type 0x" + std::string(cr))); } } @@ -8262,7 +8262,7 @@ class binary_reader std::string get_token_string() const { char cr[3]; - snprintf(cr, 3, "%.2hhX", static_cast(current)); + (std::snprintf)(cr, 3, "%.2hhX", static_cast(current)); return std::string{cr}; } @@ -11143,15 +11143,15 @@ class serializer { if (codepoint <= 0xFFFF) { - std::snprintf(string_buffer.data() + bytes, 7, "\\u%04x", - static_cast(codepoint)); + (std::snprintf)(string_buffer.data() + bytes, 7, "\\u%04x", + static_cast(codepoint)); bytes += 6; } else { - std::snprintf(string_buffer.data() + bytes, 13, "\\u%04x\\u%04x", - static_cast(0xD7C0 + (codepoint >> 10)), - static_cast(0xDC00 + (codepoint & 0x3FF))); + (std::snprintf)(string_buffer.data() + bytes, 13, "\\u%04x\\u%04x", + static_cast(0xD7C0 + (codepoint >> 10)), + static_cast(0xDC00 + (codepoint & 0x3FF))); bytes += 12; } } @@ -11187,7 +11187,7 @@ class serializer case error_handler_t::strict: { std::string sn(3, '\0'); - snprintf(&sn[0], sn.size(), "%.2X", byte); + (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)); } @@ -11268,7 +11268,7 @@ class serializer case error_handler_t::strict: { std::string sn(3, '\0'); - snprintf(&sn[0], sn.size(), "%.2X", static_cast(s.back())); + (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)); } @@ -11387,7 +11387,7 @@ class serializer static constexpr auto d = std::numeric_limits::max_digits10; // the actual conversion - std::ptrdiff_t len = snprintf(number_buffer.data(), number_buffer.size(), "%.*g", d, x); + std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(), "%.*g", d, x); // negative value indicates an error assert(len > 0);