zig icon indicating copy to clipboard operation
zig copied to clipboard

make ArrayList.replaceRange to support any overlap

Open maxzhao opened this issue 2 years ago • 0 comments

Zig Version

0.10.0-dev.4166+cae76d829.tar.xz

Steps to Reproduce and Observed Behavior

 /// trimLeft removes `str` from the left of this Zigstr, mutating it.
pub fn trimLeft(self: *Self, str: []const u8) !void {
    var list = try self.list.asList();
    const trimmed = mem.trimLeft(u8, list.items, str);
    try list.replaceRange(0, list.items.len, trimmed);
}

above code from Zigstr run's error:

 thread 31108 panic: @memcpy arguments alias
std\array_list.zig:193:30: 0x7ff772c6582f in replaceRange (test.exe.obj)
                @memcpy(range[0..new_items.len], new_items); 

because list and trimmed is overlap, but I think this is reasonable。

Expected Behavior

above code run success. make ArrayList.replaceRange to support any overlap

maxzhao avatar Jun 21 '23 02:06 maxzhao