Skip to content

fix: Clamp both of range's endpoints before subtracting - #220

Open
SamuelSchlesinger wants to merge 2 commits into
DataHaskell:mainfrom
SamuelSchlesinger:fix/range-clipping
Open

fix: Clamp both of range's endpoints before subtracting#220
SamuelSchlesinger wants to merge 2 commits into
DataHaskell:mainfrom
SamuelSchlesinger:fix/range-clipping

Conversation

@SamuelSchlesinger

Copy link
Copy Markdown

range clamped start and end - start separately, so range (8, 20) on a 10-row frame reports 10 rows and throws invalid slice (8,10,10) as soon as a column is forced, and range (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.

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.
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.

1 participant