Skip to content

Commit

Permalink
strerror_r(ev, tmp, 0) may return tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimov committed Jun 2, 2024
1 parent d1fb755 commit 38d63aa
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions include/boost/system/detail/generic_category_message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,19 @@ 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
{
if ( buffer != nullptr )
if( buffer != nullptr )
{
return strerror_r_helper( strerror_r( ev, buffer, len ), buffer );
}
else
{
// strerror_r requires non-null buffer pointer

// strerror_r requires non-null buffer pointer
char dummy_buffer[ 1 ];
return strerror_r_helper( strerror_r( ev, dummy_buffer, 0 ), buffer );
char tmp[ 1 ];
char const* r = strerror_r_helper( strerror_r( ev, tmp, 0 ), buffer );

return r == tmp? nullptr: r;
}
}

inline std::string generic_error_category_message( int ev )
Expand Down

0 comments on commit 38d63aa

Please sign in to comment.