From 3eaba7afc06004128d44da2c464a41423cf6168d Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Mon, 5 Dec 2022 20:34:46 -0800 Subject: [PATCH] Fix for sprintf deprecation warning --- include/boost/core/lightweight_test.hpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/include/boost/core/lightweight_test.hpp b/include/boost/core/lightweight_test.hpp index 3b5df89..4f10fd4 100644 --- a/include/boost/core/lightweight_test.hpp +++ b/include/boost/core/lightweight_test.hpp @@ -202,6 +202,14 @@ inline unsigned long test_output_impl( char32_t const& v ) { return v; } #pragma warning(disable: 4996) #endif +// Use snprintf if available as some complilers (clang 14.0) issue deprecation warnings for sprintf +#if ( defined(_MSC_VER) && _MSC_VER < 1900 ) || ( defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) ) || \ + ( defined(__cplusplus) && __cplusplus < 201103L) +# define BOOST_CORE_SNPRINTF(buffer, format, arg) std::sprintf(buffer, format, arg) +#else +# define BOOST_CORE_SNPRINTF(buffer, format, arg) std::snprintf(buffer, sizeof(buffer)/sizeof(buffer[0]), format, arg) +#endif + inline std::string test_output_impl( char const& v ) { if( std::isprint( static_cast( v ) ) ) @@ -211,7 +219,7 @@ inline std::string test_output_impl( char const& v ) else { char buffer[ 8 ]; - std::sprintf( buffer, "\\x%02X", static_cast( v ) ); + BOOST_CORE_SNPRINTF( buffer, "\\x%02X", static_cast( v ) ); return buffer; }