From 9b8cb7f1f674998fedcbdf85791b0d41cc8bcab4 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 24 Mar 2019 01:59:23 +0200 Subject: [PATCH] Fix wrong null character stripping for FormatMessage (Nikita Kniazev) --- include/boost/system/detail/system_category_win32.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/boost/system/detail/system_category_win32.hpp b/include/boost/system/detail/system_category_win32.hpp index ba10708..a46c8b2 100644 --- a/include/boost/system/detail/system_category_win32.hpp +++ b/include/boost/system/detail/system_category_win32.hpp @@ -126,6 +126,7 @@ inline char const * system_category_message_win32( int ev, char * buffer, std::s { r = boost::winapi::WideCharToMultiByte( code_page, 0, lpMsgBuf, -1, buffer, static_cast( len ), NULL, NULL ); boost::winapi::LocalFree( lpMsgBuf ); + if ( r != 0 ) --r; // exclude null terminator } } @@ -134,8 +135,6 @@ inline char const * system_category_message_win32( int ev, char * buffer, std::s return unknown_message_win32( ev, buffer, len ); } - --r; // exclude null terminator - while( r > 0 && ( buffer[ r-1 ] == '\n' || buffer[ r-1 ] == '\r' ) ) { buffer[ --r ] = 0;