mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-09-19 00:29:59 +00:00
Fix CMock_Guts_MemBytesCapacity() integer underflow
CMock_Guts_MemBytesCapacity() returned sizeof(CMock_Guts_Buffer), which is the size of the pointer variable itself (not the buffer it points to), minus CMOCK_MEM_ALIGN_SIZE. On a typical 64-bit build this is 8 - CMOCK_MEM_ALIGN_SIZE, which underflows to a huge garbage value whenever CMOCK_MEM_ALIGN_SIZE > sizeof(void*) (e.g. when it defaults to sizeof(max_align_t) on C11+ toolchains). Use CMock_Guts_BufferSize instead, which already tracks the real buffer size (including growth via realloc under CMOCK_MEM_DYNAMIC). This makes MemBytesCapacity() == MemBytesUsed() + MemBytesFree() by construction, matching the two sibling accessors.
This commit is contained in:
+1
-1
@@ -197,7 +197,7 @@ void* CMock_Guts_GetAddressFor(CMOCK_MEM_INDEX_TYPE index)
|
||||
*-------------------------------------------------------*/
|
||||
CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesCapacity(void)
|
||||
{
|
||||
return (sizeof(CMock_Guts_Buffer) - CMOCK_MEM_ALIGN_SIZE);
|
||||
return (CMock_Guts_BufferSize - CMOCK_MEM_ALIGN_SIZE);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user