Repository navigation
fix: Split and Values(step) reach the end when n × step alone overflows - #226
Merged
Merged
Conversation
From a negative start, n × step passes the element type's maximum one step before start + n × step does. RangeSplitting.Steps read that overflow as the end of the domain, so Int64Range, DecimalRange, Float64Range and Float32Range dropped their last values and widened the last piece, silently: [-9e18, 9e18].Values(4e18) stopped at -1e18. Steps now takes the previous boundary plus the step when the product overflows, and ends the walk only when that overflows too, which means the boundary itself has left the domain. Int32Range already computed in long and is unchanged; the temporal and NodaTime steps cannot overflow before their sum does. RangeSplitOracleTests gains a half-domain row for the five types whose step is their own element; the seed restores the old call sites and is caught on all four affected types. Closes #219 Found-By: CA Defect-Class: ALG Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Closes #219
Problem
Split(step)andValues(step)stopped early, without an error, whenn × stepoverflowed whilestart + n × stepstill fit. Each type computed the n-th boundary asstart + n * step, andRangeSplitting.Stepsread the overflow as the end of the domain.Int64Range.CreateFinite(-9e18, 9e18).Values(4e18)returned-9e18, -5e18, -1e18, andSplitreturned a last piece 10e18 wide for a 4e18 step. The same happened forDecimalRange,Float64RangeandFloat32Range.Int32Rangewas safe, because it computes inlong.Change
RangeSplitting.Stepstakes an optionalafterPrevious: the previous boundary plus one step. Whenat(start, n)overflows, it tries that. The boundary isnull(the end of the domain) only when that overflows too, which means the boundary itself has left the domain.Int64Range,DecimalRange,Float64RangeandFloat32Rangepasschecked(previous + step)orMoved(previous + step). For the integers anddecimalthis is exact, sincepreviousisstart + (n-1) × step. The floats keep the documented rule,Start + n × steprounded once, everywhere the product fits. Only where it doesn't does a boundary become the previous one plus the step. The doc comments and the docs/ranges.md bullet say so, and claim R41 follows the reworded sentence.TimeSpanorDurationproduct is bounded by the range's width, and the day and month counts are tiny. So they are unchanged.SplitandValues(step)are new in 10.0.0, and CONTRIBUTING leaves out fixes to something new in the same release. The existingAddedline already describes the behaviour.Tests
RangeSplitOracleTestsgains a half-domain row for the five types whose step is their own element type. It starts atMinValue / 2, steps byMaxValue / 3, and runs up toMaxValue. Every piece but the last must be one step long, and the last at most one step, for bothSplitandValues. Claim R39 now names this row.split-step-product-overflow-ends-early.patch. It restores the old call sites and is caught onInt64Range,DecimalRange,Float64RangeandFloat32Range(dotnet run tools/oracles.cs seeds split-step-product).RangeSplitTests.Split_AStepProductPastTheMaximum_StillReachesTheEndpins the issue's examples forInt64Range(including[-9e18, -5e18, -1e18, 3e18, 7e18]),DecimalRangeandFloat64Range.dotnet test: unit 1346, NodaTime 232, EF translation 284, conventions 395, all green.🤖 Generated with Claude Code