From 737b366279984b5725673ef94b0e144ac5eca98e Mon Sep 17 00:00:00 2001 From: xdBronch <51252236+xdBronch@users.noreply.github.com> Date: Tue, 25 Jul 2023 07:01:49 -0400 Subject: [PATCH] add error when passing a non-single-item pointer to allocator.destroy --- lib/std/mem/Allocator.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/std/mem/Allocator.zig b/lib/std/mem/Allocator.zig index 4ccd5763c5..ce1f95efd8 100644 --- a/lib/std/mem/Allocator.zig +++ b/lib/std/mem/Allocator.zig @@ -110,6 +110,7 @@ pub fn create(self: Allocator, comptime T: type) Error!*T { /// have the same address and alignment property. pub fn destroy(self: Allocator, ptr: anytype) void { const info = @typeInfo(@TypeOf(ptr)).Pointer; + if (info.size != .One) @compileError("ptr must be a single item pointer"); const T = info.child; if (@sizeOf(T) == 0) return; const non_const_ptr = @as([*]u8, @ptrCast(@constCast(ptr)));