fix(render): guard toPos / lineWrap against zero terminal column count#290
Open
SAY-5 wants to merge 1 commit intoc-bata:masterfrom
Open
fix(render): guard toPos / lineWrap against zero terminal column count#290SAY-5 wants to merge 1 commit intoc-bata:masterfrom
SAY-5 wants to merge 1 commit intoc-bata:masterfrom
Conversation
Render.toPos divided cursor by r.col without a zero-check. When the terminal reported a zero size (UpdateWinSize not called yet, the process runs under a CI runner with no TTY, input is piped in, or the ioctl returns zero for any other reason), the first keystroke path hit 'panic: runtime error: integer divide by zero' and crashed the host process (c-bata#277). Clamp col to a minimum of 1 in toPos so the prompt can still render on the first row, and skip the modulo in lineWrap when r.col is non-positive so the same crash path cannot fire from the newline branch either. Once the real window size arrives via SIGWINCH or UpdateWinSize, subsequent keystrokes behave exactly as before. Closes c-bata#277 Signed-off-by: SAY-5 <SAY-5@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes #277.
Render.toPosdividedcursorbyr.colwithout a zero check. When the terminal reported a zero column count -UpdateWinSizenot yet called, CI runner with no TTY, input piped in, orioctlreturning zero for any other reason - the first keystroke path hitpanic: runtime error: integer divide by zeroand crashed the host process.Fix
toPos: clampcolto a minimum of 1 so the prompt still renders on the first row.lineWrap: add the same guard before thecursor % r.col == 0check so the newline branch cannot fire the same crash.Once the real window size arrives via SIGWINCH or a manual
UpdateWinSizecall, subsequent keystrokes behave exactly as before.Verification
Locally on macOS, go 1.26.2:
gofmt -s -l: cleango vet ./...: cleango test -race -count=1 ./...: all packages passCloses #277