From 8fb0cedce3d7448047382aac124b953b3237525f Mon Sep 17 00:00:00 2001 From: Keith Turner Date: Mon, 13 Oct 2025 11:11:36 -0400 Subject: [PATCH] tests length of zero allocation Test code for zero length allocation was not checking the length of the returned slice was zero. Added a check for this. Also added a check for the pointer based on examining how the current code works. --- lib/std/heap.zig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/std/heap.zig b/lib/std/heap.zig index b5fd8229597b..b5f9d64a54cc 100644 --- a/lib/std/heap.zig +++ b/lib/std/heap.zig @@ -598,6 +598,8 @@ pub fn testAllocator(base_allocator: mem.Allocator) !void { // Zero-length allocation const empty = try allocator.alloc(u8, 0); + try testing.expect(empty.len == 0); + try testing.expect(empty.ptr == @as([*]u8, @ptrFromInt(std.math.maxInt(usize)))); allocator.free(empty); // Allocation with zero-sized types const zero_bit_ptr = try allocator.create(u0);