Skip to content
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

Number.slice and .static_array use unsafe casting #13033

Open
straight-shoota opened this issue Jan 31, 2023 · 0 comments
Open

Number.slice and .static_array use unsafe casting #13033

straight-shoota opened this issue Jan 31, 2023 · 0 comments
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:collection topic:stdlib:numeric

Comments

@straight-shoota
Copy link
Member

Number.slice and Number.static_array use Number.new! to cast values to the item type which does not fail on overflow errors:

Int8.slice(0x1234, 1023.0) # => Slice[52, -1]

This is unsafe behaviour and should be fixed.
The easiest fix would be to change Number.new! to Number.new. This would have a minor performance impact, but that shouldn't be too much of a problem (and safety is definitely more important).
Common usage of these macros is with number literals for which we could easily use implicit autocasting.

First reported in #13020 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:collection topic:stdlib:numeric
Projects
None yet
Development

No branches or pull requests

1 participant