1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

Merge pull request #15844 from benpicco/sys/oneway-malloc_align

sys/oneway-malloc: only allocate word-aligned chunks
This commit is contained in:
benpicco 2021-01-25 14:31:37 +01:00 committed by GitHub
commit 1862a73d41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,15 +20,23 @@
#include <string.h>
#include "architecture.h"
#include "malloc.h"
#define ENABLE_DEBUG 0
#include "debug.h"
#define ARCHITECTURE_WORD_MASK (ARCHITECTURE_WORD_BYTES - 1)
extern void *sbrk(int incr);
void __attribute__((weak)) *malloc(size_t size)
{
/* ensure we always allocate word-aligned blocks */
if (size & ARCHITECTURE_WORD_MASK) {
size += ARCHITECTURE_WORD_BYTES - (size & ARCHITECTURE_WORD_MASK);
}
if (size != 0) {
void *ptr = sbrk(size);