From 0dc29a72089ef25025e0320a9d317b56955c2954 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 20 Aug 2018 19:20:28 +0100 Subject: [PATCH] Implement suggestions from #247 --- core/mem/alloc.odin | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/mem/alloc.odin b/core/mem/alloc.odin index 267d3270e..04ecd8e2a 100644 --- a/core/mem/alloc.odin +++ b/core/mem/alloc.odin @@ -106,6 +106,9 @@ new_clone_with_allocator :: inline proc(a: Allocator, data: $T, loc := #caller_l make_slice :: proc(T: type/[]$E, auto_cast len: int, loc := #caller_location) -> T { runtime.make_slice_error_loc(loc, len); + if len == 0 { + return nil; + } data := alloc(size_of(E)*len, align_of(E)); s := Raw_Slice{data, len}; return transmute(T)s; @@ -118,7 +121,8 @@ make_dynamic_array_len :: proc(T: type/[dynamic]$E, auto_cast len: int, loc := # } make_dynamic_array_len_cap :: proc(T: type/[dynamic]$E, auto_cast len: int, auto_cast cap: int, loc := #caller_location) -> T { runtime.make_dynamic_array_error_loc(loc, len, cap); - data := alloc(size_of(E)*cap, align_of(E)); + data: rawptr; + if cap > 0 do data = alloc(size_of(E)*cap, align_of(E)); s := Raw_Dynamic_Array{data, len, cap, context.allocator}; return transmute(T)s; }