harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit a15c7d28380586cdb938737346c4b80c9cef482a
parent 4216ecda9c9af2de3bee25aac828a5144c745846
Author: Eyal Sawady <ecs@d2evs.net>
Date:   Wed,  3 Feb 2021 12:25:48 -0500

Fix rt::realloc

We can return the original pointer if the allocated size is greater than
the requested size, not if it's less than the requested size.

In addition, free the original pointer if the allocation succeeds.

Diffstat:
Mrt/malloc.ha | 3++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/rt/malloc.ha b/rt/malloc.ha @@ -155,7 +155,7 @@ export fn realloc(_p: nullable *void, n: size) nullable *void = { let p = _p: *void; let bsize = (p: uintptr - size(size): uintptr): *size; let s = *bsize; - if (s < n) { + if (s > n) { return p; }; @@ -166,6 +166,7 @@ export fn realloc(_p: nullable *void, n: size) nullable *void = { let new = malloc(n); if (new != null: nullable *void) { memcpy(new: *void, p, s); + free(p); }; return new;