mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 22:35:24 +00:00
arena_allocator/reset: fix buffer overrun
Previously, the buffer reserved with `retain_with_limit` was missing space for the `BufNode`. When the user-provided a limit that was smaller than `@sizeOf(BufNode)`, `reset` would store a new `BufNode` in an allocation smaller than `BufNode`, leading to a buffer overrun.
This commit is contained in:
parent
c16d4ab9e4
commit
41430a366f
@ -120,7 +120,7 @@ pub const ArenaAllocator = struct {
|
||||
}
|
||||
const total_size = switch (mode) {
|
||||
.retain_capacity => current_capacity,
|
||||
.retain_with_limit => |limit| std.math.min(limit, current_capacity),
|
||||
.retain_with_limit => |limit| std.math.min(@sizeOf(BufNode) + limit, current_capacity),
|
||||
.free_all => unreachable,
|
||||
};
|
||||
const align_bits = std.math.log2_int(usize, @alignOf(BufNode));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user