Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Fix indexing in ordered subsets.#6821

Merged
stephentoub merged 1 commit intodotnet:masterfrom
JonHanna:fix_6819
Mar 11, 2016
Merged

Fix indexing in ordered subsets.#6821
stephentoub merged 1 commit intodotnet:masterfrom
JonHanna:fix_6819

Conversation

@JonHanna
Copy link
Contributor

Fix off-by-one in OrderBy().Skip().Take().

Fixes #6819

Also fix handling if initial index after repeated Skip() calls overflows.

{
int minIndex = _minIndex + count;
return minIndex >= _maxIndex ? EmptyPartition<TElement>.Instance : new OrderedPartition<TElement>(_source, minIndex, _maxIndex);
return (uint)minIndex > (uint)_maxIndex ? EmptyPartition<TElement>.Instance : new OrderedPartition<TElement>(_source, minIndex, _maxIndex);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replacing >= with > is the fix for the off-by-one. Casting to (uint) is the fix for the overflow behaviour.

Copy link
Member

Choose a reason for hiding this comment

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

Can we revisit naming these minIndexInclusive / maxIndexInclusive now? ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That might not be the worse idea.

Indeed, while I've been busy with things that have kept me away from contributing and hence had the sort of ideas one only has while not working on stuff, it's occurred to me that some of these (but not this case) could be better with a _skipped and _taken, if the source is not inherently limited to being less than int.MaxValue in size. This isn't an example of that as OrderBy() can't handle larger sources anyway, but some of the others might be. I had looking at that as the next thing I wanted to look at after some Expressions tests. Maybe I should bump it, and double-checking all the other cases, up my list 😄

Fix off-by-one in OrderBy().Skip().Take().

Fixes #6819

Also fix handling if initial index after repeated Skip() calls overflows.
@stephentoub
Copy link
Member

LGTM

stephentoub added a commit that referenced this pull request Mar 11, 2016
Fix indexing in ordered subsets.
@stephentoub stephentoub merged commit ccd4043 into dotnet:master Mar 11, 2016
@VSadov
Copy link
Member

VSadov commented Mar 11, 2016

LGTM

@karelz karelz modified the milestone: 1.0.0-rtm Dec 3, 2016
@JonHanna JonHanna deleted the fix_6819 branch March 21, 2017 12:08
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Fix indexing in ordered subsets.

Commit migrated from dotnet/corefx@ccd4043
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OrderBy-Take-Skip combination gives incorrect result

6 participants