szn

Bug 277 — renderAll cursor position unclamped to pane and terminal bounds — CUP writes outside pane area

277. renderAll cursor position unclamped to pane and terminal bounds — CUP writes outside pane area

File: src/server/render.zig:344–345, 361–362, 631 Severity: MEDIUM Status: ✅ FIXED — merged-screen cursor clamped to ab.x + ab.w -| 1 / ab.y + ab.h -| 1 (pane bounds), final moveTo further clamped to self.sx -| 1 / self.sy -| 1 (terminal bounds), cur_cx advance changed from if (cw > 0) @as(u32, cw) else 1 to @as(u32, @intCast(cw)) so zero-width combining marks don’t advance the column tracker.

// OLD — no clamping:
merged_screen.cursor.x = ab.x + pane_cx;  // could exceed ab.x + ab.w
merged_screen.cursor.y = ab.y + pane_cy;
try self.moveTo(merged_screen.cursor.x, merged_screen.cursor.y); // could exceed sx/sy

// OLD — zero-width combining mark advances cur_cx by 1:
cur_cx += if (cw > 0) @as(u32, cw) else 1;

When a pane’s cursor resides at grid.width (e.g. after a character written at the last column triggers an auto-wrap), the merged display cursor was set to ab.x + grid.width — one column past the pane’s right edge. The subsequent moveTo emitted a CUP with coordinates outside both the pane and potentially the terminal bounds. Similarly, the cur_cx column tracker in renderContent was advanced by 1 for zero-width combining marks (e.g. Thai vowels), causing it to drift relative to the real terminal cursor after every combining character.

Impact: Cursor position visual misplacement after wrapping operations and after rendering combining characters; CUP escape sequences could specify out-of-bounds terminal coordinates. Five unit tests added covering: pane-bound clamp at grid.width, pane-bound clamp with offset, terminal-bound clamp, cursor clamp with non-zero pane bounds, and zero-width combining char cur_cx tracking.


NEW BUGS (2026-08-02 code audit)

Found during a fresh audit focused on cursor/movement calculation, sixel refcount accounting, memory lifecycle, and dead code. All 20 entries (#278–#297) were subsequently fixed with unit tests in rev 468–486.