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

fix: clamp smi in fast calls by default #26506

Merged
merged 2 commits into from
Oct 31, 2024
Merged

Conversation

littledivy
Copy link
Member

@nathanwhit
Copy link
Member

nathanwhit commented Oct 24, 2024

That fixes the panic but randomInt is still incorrect, the user could be wanting an int in the range 0 to Number.MAX_SAFE_INTEGER but we would clamp that and only return a value up to 2^31-1.

I think instead we should take a number (i64 probably) in the op. If it hurts perf, I guess you could have two ops (one smi) and choose based on the bounds.

@jerome-benoit
Copy link
Contributor

That fixes the panic but randomInt is still incorrect, the user could be wanting an int in the range 0 to Number.MAX_SAFE_INTEGER but we would clamp that and only return a value up to 2^31-1.

The input range supported by randomInt() is not [0, Number.MAX_SAFE_INTEGER] but [0, 281474976710655]. In case (max - min) > 281474976710655, a RangeError is thrown.

Copy link
Member

@nathanwhit nathanwhit left a comment

Choose a reason for hiding this comment

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

LGTM

@littledivy littledivy merged commit 8bfd134 into denoland:main Oct 31, 2024
17 checks passed
@littledivy littledivy deleted the core_316 branch October 31, 2024 04:40
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.

Bug: reliable panic reproduction at random generator usage
3 participants