Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/std/heap.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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))));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check for length is needed in this test, however not sure this check of the ptr is needed. Created this check based on experiments and looking at how the current code works.

allocator.free(empty);
// Allocation with zero-sized types
const zero_bit_ptr = try allocator.create(u0);
Expand Down