mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
Merge #14510: Avoid triggering undefined behaviour in base_uint<BITS>::bits()
96f6dc9fc50b1cc59e26d50940ebf46e1bdcc0ba Avoid triggering undefined behaviour in base_uint<BITS>::bits() (practicalswift) Pull request description: Avoid triggering undefined behaviour in `base_uint<BITS>::bits()`. `1 << 31` is undefined behaviour in C++11. Given the reasonable assumption of `sizeof(int) * CHAR_BIT == 32`. Tree-SHA512: 995fa38e71c8921873139ecf1b7dd54178555219af3be60d07290f379439ddd8479e3963c6f3cae8178efb61063a0f9add6cba82a5578d13888597b5bcd54f22
This commit is contained in:
parent
e14cda2d6a
commit
c89354dde2
@ -176,7 +176,7 @@ unsigned int base_uint<BITS>::bits() const
|
|||||||
for (int pos = WIDTH - 1; pos >= 0; pos--) {
|
for (int pos = WIDTH - 1; pos >= 0; pos--) {
|
||||||
if (pn[pos]) {
|
if (pn[pos]) {
|
||||||
for (int nbits = 31; nbits > 0; nbits--) {
|
for (int nbits = 31; nbits > 0; nbits--) {
|
||||||
if (pn[pos] & 1 << nbits)
|
if (pn[pos] & 1U << nbits)
|
||||||
return 32 * pos + nbits + 1;
|
return 32 * pos + nbits + 1;
|
||||||
}
|
}
|
||||||
return 32 * pos + 1;
|
return 32 * pos + 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user