Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r49093 - trunk/libs/system/src
From: bdawes_at_[hidden]
Date: 2008-10-01 14:57:48


Author: bemandawes
Date: 2008-10-01 14:57:48 EDT (Wed, 01 Oct 2008)
New Revision: 49093
URL: http://svn.boost.org/trac/boost/changeset/49093

Log:
system: reduce chance of message() throwing in response to ticket #2098
Text files modified:
   trunk/libs/system/src/error_code.cpp | 42 +++++++++++++++++++++++----------------
   1 files changed, 25 insertions(+), 17 deletions(-)

Modified: trunk/libs/system/src/error_code.cpp
==============================================================================
--- trunk/libs/system/src/error_code.cpp (original)
+++ trunk/libs/system/src/error_code.cpp 2008-10-01 14:57:48 EDT (Wed, 01 Oct 2008)
@@ -61,11 +61,12 @@
 
   const char * generic_error_category::name() const
   {
- return "GENERIC";
+ return "generic";
   }
 
   std::string generic_error_category::message( int ev ) const
   {
+ static std::string unknown_err( "Unknown error" );
   // strerror_r is preferred because it is always thread safe,
   // however, we fallback to strerror in certain cases because:
   // -- Windows doesn't provide strerror_r.
@@ -81,15 +82,19 @@
      || (defined(__osf__) && !defined(_REENTRANT))\
      || (defined(__vms))
       const char * c_str = std::strerror( ev );
- return std::string( c_str ? c_str : "Unknown error" );
- # else
+ return c_str
+ ? std::string( c_str )
+ : unknown_err;
+ # else // use strerror_r
       char buf[64];
       char * bp = buf;
       std::size_t sz = sizeof(buf);
   # if defined(__CYGWIN__) || defined(__USE_GNU)
       // Oddball version of strerror_r
       const char * c_str = strerror_r( ev, bp, sz );
- return std::string( c_str ? c_str : "Unknown error" );
+ return c_str
+ ? std::string( c_str )
+ : unknown_err;
   # else
       // POSIX version of strerror_r
       int result;
@@ -100,7 +105,9 @@
   # if defined (__sgi)
         const char * c_str = strerror( ev );
         result = 0;
- return std::string( c_str ? c_str : "Unknown error" );
+ return c_str
+ ? std::string( c_str )
+ : unknown_err;
   # else
         result = strerror_r( ev, bp, sz );
   # endif
@@ -113,26 +120,27 @@
           result = errno;
   # endif
           if ( result != ERANGE ) break;
- if ( sz > sizeof(buf) ) std::free( bp );
- sz *= 2;
- if ( (bp = static_cast<char*>(std::malloc( sz ))) == 0 )
- return std::string( "ENOMEM" );
+ if ( sz > sizeof(buf) ) std::free( bp );
+ sz *= 2;
+ if ( (bp = static_cast<char*>(std::malloc( sz ))) == 0 )
+ return std::string( "ENOMEM" );
         }
       }
+ std::string msg();
       try
       {
- std::string msg( ( result == invalid_argument ) ? "Unknown error" : bp );
- if ( sz > sizeof(buf) ) std::free( bp );
- sz = 0;
- return msg;
+ msg = ( ( result == invalid_argument ) ? "Unknown error" : bp );
       }
       catch(...)
       {
- if ( sz > sizeof(buf) ) std::free( bp );
- throw;
+ // just eat the exception
       }
- # endif
- # endif
+
+ if ( sz > sizeof(buf) ) std::free( bp );
+ sz = 0;
+ return msg;
+ # endif // else POSIX version of strerror_r
+ # endif // else use strerror_r
   }
   // system_error_category implementation --------------------------------//
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk