fix: Clamp both of range's endpoints before subtracting - #220
Open
SamuelSchlesinger wants to merge 2 commits into
Open
fix: Clamp both of range's endpoints before subtracting#220SamuelSchlesinger wants to merge 2 commits into
SamuelSchlesinger wants to merge 2 commits into
Conversation
range clips the start against [0, rows] and the length against [0, rows] independently, instead of clipping the length against the rows that remain after the start. An end past the last row slices out of bounds (range (8, 20) on ten rows dies with "invalid slice (8,10,10)"), and a negative start stretches the slice by the underflow (range (-5, 3) returns eight rows instead of three). Subtracting before clamping also wraps: range (1, minBound) reopens the range instead of emptying it. The property covers arbitrary endpoints, with an oracle that clamps before it subtracts for the same reason.
The start and the length were clipped against the row count independently, so an end past the last row produced a slice running off the end of the column and a negative start widened the slice by the underflow. Subtracting first also let a very negative end wrap to a large positive length. Clamp the start, then the end against it, and take the difference.
SamuelSchlesinger
force-pushed
the
fix/range-clipping
branch
from
August 25, 2026 08:38
05e1d0d to
a981c89
Compare
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.
rangeclampedstartandend - startseparately, sorange (8, 20)on a 10-row frame reports 10 rows and throwsinvalid slice (8,10,10)as soon as a column is forced, andrange (1, minBound)overflows into the same 10-row slice instead of an empty frame. Clamp both endpoints, then subtract.Adds a QuickCheck property against a clamp-first oracle plus three unit cases.