authorgravatar for 51252236+xdBronch@users.noreply.github.comxdBronch <51252236+xdBronch@users.noreply.github.com> 2023-07-25 07:01:49-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-25 10:55:04-07:00
log737b366279984b5725673ef94b0e144ac5eca98e
tree4c2785f9c7efe910f179333178406d8a1f695993
parentfeff968ec3b1edb0234549854b8ebbc95276bd18

add error when passing a non-single-item pointer to allocator.destroy


1 files changed, 1 insertions(+), 0 deletions(-)

lib/std/mem/Allocator.zig+1
......@@ -110,6 +110,7 @@ pub fn create(self: Allocator, comptime T: type) Error!*T {
110110/// have the same address and alignment property.
111111pub fn destroy(self: Allocator, ptr: anytype) void {
112112 const info = @typeInfo(@TypeOf(ptr)).Pointer;
113 if (info.size != .One) @compileError("ptr must be a single item pointer");
113114 const T = info.child;
114115 if (@sizeOf(T) == 0) return;
115116 const non_const_ptr = @as([*]u8, @ptrCast(@constCast(ptr)));