Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

parent_many: force a constant to u64 #51

Merged
merged 1 commit into from
Jun 26, 2024

Conversation

Davidson-Souza
Copy link
Collaborator

By default, in 64 bits machine rustc will interpret constants as u32, but in parent_many we left shift a constant by the depth of the forest, which can be grather than 32. This would a 32-bits value to be left-shifted by more than 32. This is undefined behavour and should be avoided.

This commit coerces the constants to u64, making it safe shift up to 63. Since tree with depth 63 would be impossible to see in practice (it would represent quadrilions of leaves), there's no risk of having the same UB now.

By default, in 64 bits machine rustc will interpret constants as u32,
but in parent_many we left shift a constant by the depth of the forest, which can
be grather than 32. This would a 32-bits value to be left-shifted by
more than 32. This is undefined behavour and should be avoided.

This commit coerces the constants to u64, making it safe shift up to 63.
Since tree with depth 63 would be impossible to see in practice (it
would represent quadrilions of leaves), there's no risk of having the
same UB now.
@Davidson-Souza Davidson-Souza merged commit 7ab9d5f into mit-dci:main Jun 26, 2024
20 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant