forked from boostorg/system
Fix errno_md POSIX strerror_r loop bugs (Alexander Nasonov)
[SVN r36446]
This commit is contained in:
@@ -198,21 +198,35 @@ namespace
|
|||||||
int result;
|
int result;
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if ( (result = strerror_r( ec.value(), bp, sz )) != 0 )
|
// strerror_r returns 0 on success, otherwise ERANGE if buffer too small,
|
||||||
|
// EINVAL if ec.value() not a valid error number
|
||||||
|
if ( (result = strerror_r( ec.value(), bp, sz )) == 0 )
|
||||||
|
break;
|
||||||
|
else
|
||||||
{
|
{
|
||||||
# if defined(__linux)
|
# if defined(__linux)
|
||||||
|
// Linux strerror_r returns -1 on error, with error number in errno
|
||||||
result = errno;
|
result = errno;
|
||||||
# endif
|
# endif
|
||||||
if ( result != ERANGE ) break;
|
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( ( result == EINVAL ) ? "EINVAL" : bp );
|
try
|
||||||
if ( sz > sizeof(buf) ) std::free( bp );
|
{
|
||||||
return msg;
|
std::string msg( ( result == EINVAL ) ? "EINVAL" : bp );
|
||||||
|
if ( sz > sizeof(buf) ) std::free( bp );
|
||||||
|
sz = 0;
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
catch(...)
|
||||||
|
{
|
||||||
|
if ( sz > sizeof(buf) ) std::free( bp );
|
||||||
|
throw;
|
||||||
|
}
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user