Skip to content

Conversation

keith-turner
Copy link

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.

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.
@keith-turner
Copy link
Author

Built zig locally and ran ./build/stage3/bin/zig build test-std to try out these test changes and that passed (some unrelated test failed w/ an error about a missing compression library, probably an env issue). Not sure if I am doing that correctly. Was looking for a way to run all the test in a single file and did not find that.

The documentation for Allocator.alloc is silent on zero length allocations. It seems like this documentation should define some expectations for zero length allocation for allocator users and implementers.

// 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant