Repository navigation
Fix plotting correctness, memory safety, and terminal sizing - #3
Merged
Merged
Conversation
Fit autoscaled bounds to the data so extreme points stay visible, and let omitted bounds follow the samples instead of a swapped terminal size. Store points in a growable array, draw from a heap raster, reject invalid dimensions and input, and read the window size with ioctl. Co-authored-by: Jeff Zellner <sofuture@users.noreply.github.com>
Co-authored-by: jeff.zellner <jeff.zellner@gmail.com>
Co-authored-by: jeff.zellner <jeff.zellner@gmail.com>
Co-authored-by: jeff.zellner <jeff.zellner@gmail.com>
Co-authored-by: jeff.zellner <jeff.zellner@gmail.com>
Reject UTF-8 symbols whose terminal width is not 1, draw a zero-length axis in the middle cell, and ignore SIGPIPE so a closed stdout reports a write error. Co-authored-by: Jeff Zellner <sofuture@users.noreply.github.com>
sofuture
marked this pull request as ready for review
October 11, 2026 14:45
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.
Summary
tfigwas dropping points, overflowing a heap allocation on every run, and crashing on bad dimensions. This makes the scatter plot match the data it is given and fail cleanly on bad input.double, so fractional data spreads across the chart instead of collapsing into a[0, 1]window, and large values such as1e20plot instead of failing. The largest point stays on the chart, and a cluster far from zero is no longer pinned to the origin. Bounds the user omits are fitted independently. The old defaults copied the screen height intoxmaxand the width intoymax. A zero-length axis, including a single sample, is drawn in the middle cell.-x,-X,-y, and-Yaccept fractional values. Ranges are inclusive, so a point on the maximum edge lands in the last cell. An inverted explicit range is rejected, and so is a range whose span overflows. If only one bound is given and all the data is on the wrong side of it, the window extends one unit from that bound and the plot is empty instead of failing. A trailing unpaired number no longer moves the window. Non-numeric and non-finite input exits with an error.-wand-hmust be integers from 1 to 10000. The raster is allocated on the heap, so a zero, negative, or huge size is an error instead of a stack overflow.-stakes one character that occupies one terminal column. UTF-8 scalars such as•are accepted. Wide characters, emoji, combining marks, and line separators are rejected, so the axis stays aligned with the marks.ll_newallocatedsizeof(pointer)because a variable namedlisthid the type. Points are now a growable array sized withsizeof(list). Allocation failure exits instead of dereferencing NULL.SIGPIPEis ignored, and output errors are detected when a row is written or stdout is flushed, so a closed pipe andtfig > /dev/fullboth exit with a write error. A read error on stdin is reported as one instead of as non-numeric input.ioctlon a tty or/dev/tty, thenCOLUMNSandLINES. Thesttyfallback, which printed errors on Linux, is gone. Each plot row is written in one shot.Test plan
make testchecks the README figure, autoscaled integers, fractional data and bounds, huge coordinates, a centered single sample, a vertical line on a zero-width axis, negative values, a far cluster, partial bounds (including one that excludes all the data), inclusive edges, odd input, a one-column UTF-8 symbol, and rejected wide, combining, and separator symbols, dimensions, ranges, and non-numeric input. It also checks writing to/dev/full, a closed stdout pipe, and reading from an unreadable stdin.makeis clean with-Wall -Wextra -pedantic.