Skip to content

std.ArrayList: shrinkRetainingCapacity and clearRetainingCapacity should memset to undefined #25796

@mateusz834

Description

@mateusz834

Considering that:

zig/lib/std/array_list.zig

Lines 378 to 388 in ee4df4a

/// Reduce length to `new_len`.
/// Invalidates element pointers for the elements `items[new_len..]`.
/// Asserts that the new length is less than or equal to the previous length.
pub fn shrinkRetainingCapacity(self: *Self, new_len: usize) void {
assert(new_len <= self.items.len);
self.items.len = new_len;
}
/// Invalidates all element pointers.
pub fn clearRetainingCapacity(self: *Self) void {
self.items.len = 0;

Both Invalidate pointers to elements, shouldn't we also set all the elements to undefined for better runtime safety?

Let me know, if so i will send a PR for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions