szn

Bug 532 — evictOldestIfFull underflows on max_buffers == 0

532. Unguarded eviction when the capacity is zero

Severity: LOW Status: ✅ FIXED Files: src/buffer.zig:30-36

Problem

fn evictOldestIfFull(self: *BufferList) void {
    if (self.items.items.len < self.max_buffers) return;
    const oldest = self.items.items[self.items.items.len - 1];
    ...
}

When max_buffers == 0, the early return is skipped for an empty list (0 < 0 is false), so the next line reads items.items[-1] and panics (index out of bounds). max_buffers defaults to 50 and is not wired to any option today, so this is unreachable in production, but the guard does not express the intended invariant.

Proposed Fix

if (self.max_buffers == 0 or self.items.items.len < self.max_buffers) return;

or treat max_buffers == 0 as “evict everything on push”.

Fix

Guard the eviction path against a zero capacity:

if (self.max_buffers == 0 or self.items.items.len < self.max_buffers) return;

max_buffers == 0 is now treated as “unlimited” rather than trapping. A regression test (buffer list with max_buffers=0 does not panic on push — bug #532) exercises the previously panicking path.

Verification status

Fixed and verified with zig build test on Zig 0.16.0 (and build on 0.17.0).

Bug #363 (bounded paste-buffer retention).