1
0
mirror of https://gitlab.com/rnger/amath synced 2025-11-20 09:13:08 +00:00

Zero out allocated memory

This commit is contained in:
2021-01-30 17:42:13 +01:00
parent d7fe11d56a
commit 811644f4c7

View File

@ -37,7 +37,7 @@
#include <clib/exec_protos.h>
#define ALLOC_LIST(x) AllocVec(x, MEMF_ANY | MEMF_CLEAR)
#define FREE_LIST(x) FreeVec(x)
#define ALLOC_MEM(x, y) AllocPooled(x, y)
#define ALLOC_MEM(x, y) AllocPooledZero(x, y)
#define FREE_MEM(x, y, z) FreePooled(x, y, z)
#define Debug(x, y, z)
#else
@ -85,6 +85,31 @@ struct MemoryList *list = nullptr;
void alloc_error(char *, size_t);
void dealloc_error(char *, void *);
#if defined(AMIGA)
static void MemZero(void *address, ULONG size)
{
char *c = (char *)address;
int n = size;
do
{
*c++ = '\0';
} while (--n);
}
static void *AllocPooledZero(void *pool, size_t size)
{
ULONG memSize = (ULONG)size;
void *memory = AllocPooled(pool, memSize);
if (memory != NULL)
{
MemZero(memory, memSize);
}
return memory;
}
#endif
/**
* @brief Allocate memory and add it to the global memory list.
*/
@ -112,11 +137,11 @@ void *AllocMemSafe(size_t size)
}
#ifdef P64BIT
// Align to bytes of 8
allocsize = (size + 7) & ~0x07;
// Align to bytes of 8, remove 0 bytes allocations
allocsize = (size + 8) & ~0x07;
#else
// Align to bytes of 4
allocsize = (size + 3) & ~0x03;
// Align to bytes of 4, remove 0 bytes allocations
allocsize = (size + 4) & ~0x03;
#endif
newblock = (struct MemoryBlock *)ALLOC_MEM(list->pool, sizeof(struct MemoryBlock));