🟡 Nuanced off-by-one in _wrap_text_token when break_gi > ng #18

Open xenolandscapes.com
Open opened by xenolandscapes.com

Summary #

Fix for nil byte_offsets access when break exceeds grapheme count may still have edge case with zero-width graphemes.

The Problem #

In src/cursed/view/view_token.lua lines 83-111, the fix adds handling for when break_gi > ng. It uses tok.buf_end and loops to ng. However, if there are zero-width graphemes (width 0), col + gw does not increase the column, but the grapheme is still counted. The overflow condition col + gw > ww and col > 0 could be satisfied before any column advance, leading to an immediate break with break_gi = i. If i is 1 and col is 0, the condition fails because col > 0 is required. But if col is 0 and the first grapheme is zero-width, it won't break and will accumulate. That could cause the row to never flush if all graphemes are zero-width. But the earlier fix for overflow with spaces already addresses part of this. Not a high-risk issue.

Impact #

  • category: correctness
  • description: edge case in _wrap_text_token with zero-width graphemes; unlikely to cause visible issues

No action needed unless zero-width graphemes without spaces cause an infinite loop. Otherwise, the fix is correct.


Commit range: fa5e67a..fa5e67a
Code Review: CR-2026-07-27-11

Sign up or Sign in to add to the discussion.