Skip to content

Avoid division by zero on small windows - #214

Merged
tenox7 merged 2 commits into
tenox7:masterfrom
edgar-bonet:no-fpe
Mar 15, 2026
Merged

tenox7 merged 2 commits into
tenox7:masterfrom
edgar-bonet:no-fpe

Conversation

@edgar-bonet

Copy link
Copy Markdown
Collaborator

If the window is too small when the program starts, ttyplot crashes on a division by zero (“Floating-point exception”). This is because plotwidth never gets set to a non-zero value, and handle_value() performs a modulo operation with plotwidth as the denominator.

This pull request fixes the crash by initializing plotwidth with the minimum value it can sensibly have.

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.
@edgar-bonet
edgar-bonet requested review from hartwork and tenox7 and removed request for hartwork March 8, 2026 14:02

@hartwork hartwork left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@edgar-bonet nice one! I confirm crasher COLUMNS=1 ./ttyplot <<<"1 2 3 4" fixed.

@tenox7
tenox7 merged commit f2837df into tenox7:master Mar 15, 2026
8 checks passed
@tenox7

tenox7 commented Mar 15, 2026

Copy link
Copy Markdown
Owner

thank you!

@edgar-bonet
edgar-bonet deleted the no-fpe branch March 15, 2026 10:06
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
ttyplot 1.7.5

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## What's Changed
* Fix CI failure on maybe-uninitialized compiler warning by @edgar-bonet in tenox7/ttyplot#205
* CI: upgrade macOS runners by @edgar-bonet in tenox7/ttyplot#206
* Actions(deps): Bump codespell-project/actions-codespell from 2.1 to 2.2 by @dependabot[bot] in tenox7/ttyplot#208
* Avoid division by zero on small windows by @edgar-bonet in tenox7/ttyplot#214
* `ttyplot.c`: Fix in-code comment by @hartwork in tenox7/ttyplot#217
* Work on smaller windows with no clock display by @edgar-bonet in tenox7/ttyplot#215


**Full Changelog**: https://github.com/tenox7/ttyplot/compare/1.7.4...1.7.5</pre>
  <p>View the full release notes at <a href="https://github.com/tenox7/ttyplot/releases/tag/1.7.5">https://github.com/tenox7/ttyplot/releases/tag/1.7.5</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!12187
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants