diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-11-13 20:33:13 +0200 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-11-16 01:12:27 +0200 |
| commit | b6b3462796fe38a071e6ed2cbcdbb5b024359f35 (patch) | |
| tree | a27dc4a4b577c70aa478dedc0704ef5404e4423a /lib/std | |
| parent | 11c64bfe6ec921a481b340392ab1d2377359586d (diff) | |
| download | zig-b6b3462796fe38a071e6ed2cbcdbb5b024359f35.tar.gz zig-b6b3462796fe38a071e6ed2cbcdbb5b024359f35.zip | |
std.mem.Allocator: do not return undefined pointers from `create`
Closes #13517
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/mem/Allocator.zig | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/std/mem/Allocator.zig b/lib/std/mem/Allocator.zig index 28ca194c29..92347c0919 100644 --- a/lib/std/mem/Allocator.zig +++ b/lib/std/mem/Allocator.zig @@ -167,7 +167,7 @@ pub inline fn rawFree(self: Allocator, buf: []u8, buf_align: u29, ret_addr: usiz /// Returns a pointer to undefined memory. /// Call `destroy` with the result to free the memory. pub fn create(self: Allocator, comptime T: type) Error!*T { - if (@sizeOf(T) == 0) return @as(*T, undefined); + if (@sizeOf(T) == 0) return @intToPtr(*T, std.math.maxInt(usize)); const slice = try self.allocAdvancedWithRetAddr(T, null, 1, .exact, @returnAddress()); return &slice[0]; } |
