commit 48519b9c63ac9fb07d4f00261ad77afa6f1990af
parent c5c5a7371aa1eb55b6224186e329b8c5cd5e112c
Author: Drew DeVault <sir@cmpwn.com>
Date: Fri, 12 Feb 2021 14:13:46 -0500
rt::realloc: accept 0 for input
Diffstat:
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/rt/malloc.ha b/rt/malloc.ha
@@ -144,8 +144,9 @@ fn free_small(p: *void, s: size) void = {
// in-place. Returns null if there is insufficient memory to support the
// request.
export fn realloc(_p: nullable *void, n: size) nullable *void = {
- assert(n > 0);
- if (_p == null) {
+ if (n == 0) {
+ return null;
+ } else if (_p == null) {
return malloc(n);
};