diff options
| author | gingerBill <bill@gingerbill.org> | 2020-04-12 10:41:44 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-04-12 10:41:44 +0100 |
| commit | 9e698b720f4f26341db81b70ea5f70f5bdfd9e3a (patch) | |
| tree | 61f09e4ea24b8e0441e77fc0c62b3ed8ea56e3c9 /core/mem/alloc.odin | |
| parent | 5157619eb7d0ab40d54cbc0562cc3ce4a5526e81 (diff) | |
Change behaviour for zero-sized value types of array-related types; Fix make behaviour to always zero memory
Diffstat (limited to 'core/mem/alloc.odin')
| -rw-r--r-- | core/mem/alloc.odin | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/core/mem/alloc.odin b/core/mem/alloc.odin index 767e59183..fda7862c3 100644 --- a/core/mem/alloc.odin +++ b/core/mem/alloc.odin @@ -111,7 +111,10 @@ make_slice :: inline proc($T: typeid/[]$E, auto_cast len: int, allocator := cont make_aligned :: proc($T: typeid/[]$E, auto_cast len: int, alignment: int, allocator := context.allocator, loc := #caller_location) -> T { runtime.make_slice_error_loc(loc, len); data := alloc(size_of(E)*len, alignment, allocator, loc); - if data == nil do return nil; + if data == nil && size_of(E) != 0 { + return nil; + } + zero(data, size_of(E)*len); s := Raw_Slice{data, len}; return transmute(T)s; } @@ -125,9 +128,10 @@ make_dynamic_array_len_cap :: proc($T: typeid/[dynamic]$E, auto_cast len: int, a runtime.make_dynamic_array_error_loc(loc, len, cap); data := alloc(size_of(E)*cap, align_of(E), allocator, loc); s := Raw_Dynamic_Array{data, len, cap, allocator}; - if data == nil { + if data == nil && size_of(E) != 0 { s.len, s.cap = 0, 0; } + zero(data, size_of(E)*len); return transmute(T)s; } make_map :: proc($T: typeid/map[$K]$E, auto_cast cap: int = 16, allocator := context.allocator, loc := #caller_location) -> T { |