in case of mmap-obtained chunks, end points past the end of the
mapping and reading it may fault. since the value is not needed until
after the conditional, move the access to prevent invalid reads.
return NULL;
header = ((size_t *)mem)[-1];
- end = mem + (header & -8);
- footer = ((size_t *)end)[-2];
new = (void *)((uintptr_t)mem + align-1 & -align);
if (!(header & 7)) {
return new;
}
+ end = mem + (header & -8);
+ footer = ((size_t *)end)[-2];
+
((size_t *)mem)[-1] = header&7 | new-mem;
((size_t *)new)[-2] = footer&7 | new-mem;
((size_t *)new)[-1] = header&7 | end-new;