Skip to content

Commit

Permalink
Fix coverity issue in block::initEmptyBlock (#1491)
Browse files Browse the repository at this point in the history
getObjectSize should not return values bigger then 2^16-1.
We are assigning it's return value, which is 32 bit to 16 bit one,
so it is good to assert it anyway.
  • Loading branch information
lplewa authored Sep 3, 2024
1 parent bca0235 commit 2d5b10f
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/tbbmalloc/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ unsigned int getSmallObjectIndex(unsigned int size)
/*
* Depending on indexRequest, for a given size return either the index into the bin
* for objects of this size, or the actual size of objects in this bin.
* TODO: Change return type to unsigned short.
*/
template<bool indexRequest>
static unsigned int getIndexOrObjectSize (unsigned int size)
Expand Down Expand Up @@ -1581,6 +1582,7 @@ void Block::initEmptyBlock(TLSData *tls, size_t size)
unsigned int objSz = getObjectSize(size);

cleanBlockHeader();
MALLOC_ASSERT(objSz <= USHRT_MAX, "objSz must not be less 2^16-1");
objectSize = objSz;
markOwned(tls);
// bump pointer should be prepared for first allocation - thus mode it down to objectSize
Expand Down

0 comments on commit 2d5b10f

Please sign in to comment.