| author | |
| committer | |
| log | fedff060790733b85582b733cfea9fefb168deb6 |
| tree | 2b5487f551ce91c05741fddf12a90d3ef4e46859 |
| parent | aa902c7042402d4602797f91ef8ec8b96cb179a7 |
The buffer `buf` contains N (= `slice_sizes.len`) slices followed by the
N null-terminated arguments. The N null-terminated arguments are stored
in the `contents` array list. Thus, `buf` size should be:
@sizeOf([]u8) * slice_sizes.len + contents_slice.len
Instead of:
@sizeOf([]u8) * slice_sizes.len + contents_slice.len + slice_sizes.len
This bug was found thanks to the gpa allocator which checks if freed
size matches allocated sizes for large allocations.1 files changed, 1 insertions(+), 2 deletions(-)
lib/std/process.zig+1-2| ... | ... | @@ -557,9 +557,8 @@ pub fn argsAlloc(allocator: mem.Allocator) ![][:0]u8 { |
| 557 | 557 | |
| 558 | 558 | const contents_slice = contents.items; |
| 559 | 559 | const slice_sizes = slice_list.items; |
| 560 | const contents_size_bytes = try math.add(usize, contents_slice.len, slice_sizes.len); | |
| 561 | 560 | const slice_list_bytes = try math.mul(usize, @sizeOf([]u8), slice_sizes.len); |
| 562 | const total_bytes = try math.add(usize, slice_list_bytes, contents_size_bytes); | |
| 561 | const total_bytes = try math.add(usize, slice_list_bytes, contents_slice.len); | |
| 563 | 562 | const buf = try allocator.alignedAlloc(u8, @alignOf([]u8), total_bytes); |
| 564 | 563 | errdefer allocator.free(buf); |
| 565 | 564 |