libstd: modify wrong shift width #6108
Merged
+39
−21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
std::bigint
contains the following code.The code above contains a bug that the value of the right operand of the shift operator exceeds the size of the left operand,
because sizeof(*elem) == 32, and 0 <= n_bits < 32 in 64bit architecture.
If
--opt-level
option is not given to rustc, the code above runs as if the right operand is(uint::bits - n_bits) % 32
,but if --opt-level is given,
borrow
is always zero.I wonder why this bug is not catched in the libstd's testsuite (I try the
rustc --test --opt-level=2 bigint.rs
before fixing the bug,but the unittest passes normally.)
This pull request also removes the implicit vector copies in
bigint.rs
.