szn

Bug 469 — Copy-mode placeCursorAtLogical leaves cursor_y unclamped with unchecked casts

469. Unclamped cursor row + narrowing casts

Severity: MEDIUM Status: ✅ FIXED Files: src/mode_copy.zig


Root Cause Analysis

In src/mode_copy.zig:552-564:

physical_line = logical + x / width; phys_x = x % width;
if (physical_line < hist_len) { ...; y = 0; }
else { scroll = 0; y = @intCast(physical_line - hist_len); } // can be >= height
x = @intCast(phys_x);

y is never clamped to height-1. All three @intCast (usize→u32) panic if history/grid ever exceed u32.

Proposed Fix

Clamp y to height -| 1 and saturate/check casts (@min / std.math.cast). Add a test with a tall logical line exceeding viewport height.