Avoid division by zero on small windows#214
Open
edgar-bonet wants to merge 2 commits intotenox7:masterfrom
Open
Avoid division by zero on small windows#214edgar-bonet wants to merge 2 commits intotenox7:masterfrom
edgar-bonet wants to merge 2 commits intotenox7:masterfrom
Conversation
If the window is too small when the program starts, plotwidth stays at
zero. As soon as data arrives, handle_value() computes the appropriate
array index to store it, as
n = (n + 1) % plotwidth;
The division by zero makes the program crash with SIGFPE (Floating-point
exception).
Avoid the crash by initializing plotwidth to the smallest value it can
sensibly have.
hartwork
approved these changes
Mar 8, 2026
Collaborator
hartwork
left a comment
There was a problem hiding this comment.
@edgar-bonet nice one! I confirm crasher COLUMNS=1 ./ttyplot <<<"1 2 3 4" fixed.
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.
If the window is too small when the program starts, ttyplot crashes on a division by zero (“Floating-point exception”). This is because
plotwidthnever gets set to a non-zero value, andhandle_value()performs a modulo operation withplotwidthas the denominator.This pull request fixes the crash by initializing
plotwidthwith the minimum value it can sensibly have.