Skip to content

Commit

Permalink
Alloc at least 1 elem in pool_t block_ptrs. (flame#560)
Browse files Browse the repository at this point in the history
Details:
- Previously, the block_ptrs field of the pool_t was allowed to be
  initialized as any unsigned integer, including 0. However, a length of
  0 could be problematic given that malloc(0) is undefined and therefore
  variable across implementations. As a safety measure, we check for
  block_ptrs array lengths of 0 and, in that case, increase them to 1.
- Co-authored-by: Minh Quan Ho <[email protected]>

Change-Id: I1e885d887aaba5e73df091ef52e6c327fd6418de
  • Loading branch information
hominhquan authored and dzambare committed Aug 1, 2022
1 parent 3c01fcb commit 6d4d6a7
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions frame/base/bli_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ void bli_pool_init
// Make sure that block_ptrs_len is at least num_blocks.
block_ptrs_len = bli_max( block_ptrs_len, num_blocks );

// Handle the case where block_ptrs_len is zero, we explicitly set it to 1,
// to avoid any malloc() with zero size, whose behavior is not fixed, and
// also to prevent from falling into any further memory corruption bug.
block_ptrs_len = ( block_ptrs_len == 0 ) ? 1 : block_ptrs_len;

#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_pool_init(): allocating block_ptrs (length %d): ",
( int )block_ptrs_len );
Expand Down

0 comments on commit 6d4d6a7

Please sign in to comment.