From 336efa141461f69182c9f04a67986a834d2858e3 Mon Sep 17 00:00:00 2001 From: Mohammad Nejati Date: Sun, 2 Jun 2024 10:31:24 +0000 Subject: [PATCH] strerror_r requires non-null buffer pointer Fixes -Wnonnull warnings when calling message with a nullptr buffer --- include/boost/system/detail/generic_category_message.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/boost/system/detail/generic_category_message.hpp b/include/boost/system/detail/generic_category_message.hpp index ded2db63..3b75ade9 100644 --- a/include/boost/system/detail/generic_category_message.hpp +++ b/include/boost/system/detail/generic_category_message.hpp @@ -39,7 +39,12 @@ inline char const * strerror_r_helper( int r, char const * buffer ) noexcept inline char const * generic_error_category_message( int ev, char * buffer, std::size_t len ) noexcept { - return strerror_r_helper( strerror_r( ev, buffer, len ), buffer ); + if ( buffer != nullptr ) + return strerror_r_helper( strerror_r( ev, buffer, len ), buffer ); + + // strerror_r requires non-null buffer pointer + char dummy_buffer[ 1 ]; + return strerror_r_helper( strerror_r( ev, dummy_buffer, 0 ), buffer ); } inline std::string generic_error_category_message( int ev )