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.
This commit is contained in:
Keith Turner 2025-10-13 11:11:36 -04:00
parent 87c18945c2
commit 8fb0cedce3

View file

@ -598,6 +598,8 @@ pub fn testAllocator(base_allocator: mem.Allocator) !void {
// Zero-length allocation // Zero-length allocation
const empty = try allocator.alloc(u8, 0); 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); allocator.free(empty);
// Allocation with zero-sized types // Allocation with zero-sized types
const zero_bit_ptr = try allocator.create(u0); const zero_bit_ptr = try allocator.create(u0);