Skip to content

Commit 737b366

Browse files
xdBronchandrewrk
authored andcommitted
add error when passing a non-single-item pointer to allocator.destroy
1 parent feff968 commit 737b366

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

lib/std/mem/Allocator.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ pub fn create(self: Allocator, comptime T: type) Error!*T {
110110
/// have the same address and alignment property.
111111
pub 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)));

0 commit comments

Comments
 (0)