Handle zero-length allocations in AlignedBuffer.
This commit is contained in:
@@ -75,11 +75,9 @@ uint64_t Crypto::unique( void )
|
|||||||
AlignedBuffer::AlignedBuffer( size_t len, const char *data )
|
AlignedBuffer::AlignedBuffer( size_t len, const char *data )
|
||||||
: m_len( len ), m_allocated( NULL ), m_data( NULL )
|
: m_len( len ), m_allocated( NULL ), m_data( NULL )
|
||||||
{
|
{
|
||||||
|
size_t alloc_len = len ? len : 1;
|
||||||
#if defined(HAVE_POSIX_MEMALIGN)
|
#if defined(HAVE_POSIX_MEMALIGN)
|
||||||
if ( len == 0 ) {
|
if ( ( 0 != posix_memalign( &m_allocated, 16, alloc_len ) )
|
||||||
len = 1;
|
|
||||||
}
|
|
||||||
if ( ( 0 != posix_memalign( &m_allocated, 16, len ) )
|
|
||||||
|| ( m_allocated == NULL ) ) {
|
|| ( m_allocated == NULL ) ) {
|
||||||
throw std::bad_alloc();
|
throw std::bad_alloc();
|
||||||
}
|
}
|
||||||
@@ -88,7 +86,7 @@ AlignedBuffer::AlignedBuffer( size_t len, const char *data )
|
|||||||
#else
|
#else
|
||||||
/* malloc() a region 15 bytes larger than we need, and find
|
/* malloc() a region 15 bytes larger than we need, and find
|
||||||
the aligned offset within. */
|
the aligned offset within. */
|
||||||
m_allocated = malloc( 15 + len );
|
m_allocated = malloc( 15 + alloc_len );
|
||||||
if ( m_allocated == NULL ) {
|
if ( m_allocated == NULL ) {
|
||||||
throw std::bad_alloc();
|
throw std::bad_alloc();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user