mirror of
https://gitlab.com/rnger/amath
synced 2026-09-11 19:57:25 +00:00
Zero out allocated memory
This commit is contained in:
+30
-5
@@ -37,7 +37,7 @@
|
|||||||
#include <clib/exec_protos.h>
|
#include <clib/exec_protos.h>
|
||||||
#define ALLOC_LIST(x) AllocVec(x, MEMF_ANY | MEMF_CLEAR)
|
#define ALLOC_LIST(x) AllocVec(x, MEMF_ANY | MEMF_CLEAR)
|
||||||
#define FREE_LIST(x) FreeVec(x)
|
#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 FREE_MEM(x, y, z) FreePooled(x, y, z)
|
||||||
#define Debug(x, y, z)
|
#define Debug(x, y, z)
|
||||||
#else
|
#else
|
||||||
@@ -85,6 +85,31 @@ struct MemoryList *list = nullptr;
|
|||||||
void alloc_error(char *, size_t);
|
void alloc_error(char *, size_t);
|
||||||
void dealloc_error(char *, void *);
|
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.
|
* @brief Allocate memory and add it to the global memory list.
|
||||||
*/
|
*/
|
||||||
@@ -112,11 +137,11 @@ void *AllocMemSafe(size_t size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef P64BIT
|
#ifdef P64BIT
|
||||||
// Align to bytes of 8
|
// Align to bytes of 8, remove 0 bytes allocations
|
||||||
allocsize = (size + 7) & ~0x07;
|
allocsize = (size + 8) & ~0x07;
|
||||||
#else
|
#else
|
||||||
// Align to bytes of 4
|
// Align to bytes of 4, remove 0 bytes allocations
|
||||||
allocsize = (size + 3) & ~0x03;
|
allocsize = (size + 4) & ~0x03;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
newblock = (struct MemoryBlock *)ALLOC_MEM(list->pool, sizeof(struct MemoryBlock));
|
newblock = (struct MemoryBlock *)ALLOC_MEM(list->pool, sizeof(struct MemoryBlock));
|
||||||
|
|||||||
Reference in New Issue
Block a user