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:
94xhn
2026-07-15 05:17:12 +08:00
parent 374c7569d1
commit c30e6bb022
+1 -1
View File
@@ -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);
}
/*-------------------------------------------------------