diff options
-rw-r--r-- | qstd/memory.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/qstd/memory.c b/qstd/memory.c index 1dac1c5..7d669d2 100644 --- a/qstd/memory.c +++ b/qstd/memory.c @@ -109,11 +109,13 @@ void* imp2_heap_alloc( phdr[0] |= f; return phdr + 1; } else { - int ns = bs - as; - if (ns > hs * 2) { - int* nhdr = (int*)&h->buf[o + ns]; - phdr[0] = ns; - nhdr[0] = as | f; + int ps = bs - as; + int aps = align_size(ps, hs) - hs; + if (aps > hs * 2) { + int* nhdr = (int*)&h->buf[o + aps]; + assert(aligned(nhdr, sizeof hs)); + phdr[0] = aps; + nhdr[0] = (as + (ps - aps)) | f; h->blocks++; return &nhdr[1]; } |