Skip to content

Commit

Permalink
Added a few more memory alignments when using both primary and extra …
Browse files Browse the repository at this point in the history
…memory in a back-to-back memory allocation.
  • Loading branch information
gutschke committed Jan 24, 2024
1 parent f72893f commit 8e7fb7b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions microstack/ILibParsers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,8 @@ void* ILibMemory_SmartReAllocate(void *ptr, size_t len)
size_t originalRawSize = ILibMemory_Init_Size(ILibMemory_Size(ptr), ILibMemory_ExtraSize(ptr));
size_t originalSize = ILibMemory_Size(ptr);
size_t originalExtraSize = ILibMemory_ExtraSize(ptr);
if (originalExtraSize)
len = (len + sizeof(void *) - 1) & -sizeof(void *);
size_t newRawSize = ILibMemory_Init_Size(len, originalExtraSize);

if (newRawSize < originalRawSize && originalExtraSize > 0)
Expand Down
2 changes: 1 addition & 1 deletion microstack/ILibParsers.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ int ILibIsRunningOnChainThread(void* chain);
#define ILibMemory_FromRaw(ptr) ((char*)(ptr) + sizeof(ILibMemory_Header))

#define ILibMemory_Size_Validate(primaryLen, extraLen) (((size_t)(primaryLen)<(UINT32_MAX - (size_t)(extraLen)))&&((size_t)(extraLen)<(UINT32_MAX-(size_t)(primaryLen)))&&((size_t)((primaryLen) + (extraLen))<(UINT32_MAX - sizeof(ILibMemory_Header)))&&((extraLen)==0 || ((size_t)((primaryLen)+(extraLen)+sizeof(ILibMemory_Header))<(UINT32_MAX-sizeof(ILibMemory_Header)))))
#define ILibMemory_Init_Size(primaryLen, extraLen) (primaryLen + extraLen + sizeof(ILibMemory_Header) + (extraLen>0?sizeof(ILibMemory_Header):0))
#define ILibMemory_Init_Size(primaryLen, extraLen) (primaryLen + extraLen + sizeof(ILibMemory_Header) + (extraLen>0?sizeof(ILibMemory_Header) + (((primaryLen + sizeof(ILibMemory_Header)) + sizeof(void *) - 1) & - sizeof(void *)):0))
void* ILibMemory_Init(void *ptr, size_t primarySize, size_t extraSize, ILibMemory_Types memType);
#define ILibMemory_SmartAllocate(len) ILibMemory_InitEx(ILibMemory_Size_Validate(len,0)?malloc(ILibMemory_Init_Size(len, 0)):NULL, (int)len, 0, ILibMemory_Types_HEAP)
#define ILibMemory_SmartAllocateEx(primaryLen, extraLen) ILibMemory_InitEx(ILibMemory_Size_Validate(primaryLen,extraLen)?malloc(ILibMemory_Init_Size(primaryLen, extraLen)):NULL, (int)primaryLen, (int)extraLen, ILibMemory_Types_HEAP)
Expand Down

0 comments on commit 8e7fb7b

Please sign in to comment.