-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Number::StepIterator overflow #10295
Fix Number::StepIterator overflow #10295
Conversation
The same overflow happens with the yielding method as well. The implementation looks very hard to follow. I'll give it a try to find a better solution. |
Oh damn: It just needs to be |
spec/std/number_spec.cr
Outdated
it_iterates "UInt8 upwards", (UInt8::MIN.to_i..UInt8::MAX.to_i).map(&.to_u8), (UInt8::MIN..UInt8::MAX).step(by: 1) | ||
it_iterates "UInt8 downwards", (UInt8::MIN.to_i..UInt8::MAX.to_i).map(&.to_u8).reverse, (UInt8::MAX..UInt8::MIN).step(by: -1) | ||
|
||
it { (Int8::MIN..Int8::MAX).each.count { true }.should eq(256) } | ||
it_iterates "Int8 upwards", (Int8::MIN.to_i..Int8::MAX.to_i).map(&.to_i8), (Int8::MIN..Int8::MAX).step(by: 1) | ||
it_iterates "Int8 downwards", (Int8::MIN.to_i..Int8::MAX.to_i).map(&.to_i8).reverse, (Int8::MAX..Int8::MIN).step(by: -1) | ||
|
||
it { (Int16::MIN..Int16::MAX).each.count { true }.should eq(65536) } | ||
it_iterates "Int16 upwards", (Int16::MIN.to_i..Int16::MAX.to_i).map(&.to_i16), (Int16::MIN..Int16::MAX).step(by: 1) | ||
it_iterates "Int16 downwards", (Int16::MIN.to_i..Int16::MAX.to_i).map(&.to_i16).reverse, (Int16::MAX..Int16::MIN).step(by: -1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Collecting the entire ranges in arrays isn't super efficient, but not a big deal either. Using it_iterates
ensures these test are run against both step
methods.
Cool LGTM. I will need your approval on the PR to merge your changes once the CI is happy. |
Before this PR the
Number::StepIterator#next
could raise because oflimit - @current
Fixes a regression introduced in #10130