From 2d5b10f2d40b1003a4797d806f6fdd8e5d952f8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Plewa?= Date: Tue, 3 Sep 2024 17:14:50 +0200 Subject: [PATCH] Fix coverity issue in block::initEmptyBlock (#1491) 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. --- src/tbbmalloc/frontend.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tbbmalloc/frontend.cpp b/src/tbbmalloc/frontend.cpp index 77f9d6594e..c9aaf46337 100644 --- a/src/tbbmalloc/frontend.cpp +++ b/src/tbbmalloc/frontend.cpp @@ -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 static unsigned int getIndexOrObjectSize (unsigned int size) @@ -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