summaryrefslogtreecommitdiff
path: root/qstd/memory.c
diff options
context:
space:
mode:
Diffstat (limited to 'qstd/memory.c')
-rw-r--r--qstd/memory.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/qstd/memory.c b/qstd/memory.c
index 91e4a5b..f245289 100644
--- a/qstd/memory.c
+++ b/qstd/memory.c
@@ -95,24 +95,25 @@ void* imp2_heap_alloc(
for (i = o = 0; i < h->blocks; i++) {
int* phdr = (int*)&h->buf[o];
int hdr = *phdr, bs;
- assert(aligned(phdr, sizeof hdr));
bs = hdr & ~f;
+ assert(bs);
+ assert(aligned(phdr, sizeof hdr));
if (~hdr & f) {
if (as == bs) {
- phdr[0] |= 1;
+ phdr[0] |= f;
return phdr + 1;
} else {
int ns = bs - as;
- if (ns > hs) {
- int* nhdr = &phdr[ns / 4];
+ if (ns > hs * 2) {
+ int* nhdr = (int*)&h->buf[o + ns];
phdr[0] = ns;
nhdr[0] = as | f;
h->blocks++;
return &nhdr[1];
}
}
- } else
- o += bs;
+ }
+ o += bs;
}
return 0;
}