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.
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.
175 | @@ -176,7 +176,7 @@ unsigned int base_uint<BITS>::bits() const 176 | for (int pos = WIDTH - 1; pos >= 0; pos--) { 177 | if (pn[pos]) { 178 | for (int nbits = 31; nbits > 0; nbits--) { 179 | - if (pn[pos] & 1 << nbits) 180 | + if (pn[pos] & 1U << nbits)
pn[...] is uint32_t, how is this ever undefined behavior?
I don't think C ever "promotes" uint32_t to int.
so let's make the counter an 'unsigned' then? edit: oh, never mind, it's counting down, that wouldn't really work either...
Can you add a test that fails without this fix?
no, he can't—the whole problem, the whole shitshow with C and C++ is that you can't predict what will happen with undefined behavior—it can just work with one compiler or version and commit war crimes the next one
@promag How would one test for the presence of undefined behaviour? :-)
If you are referring to the sanitisers there are no sanitisers flagging this UB AFAIK.
utACK 96f6dc9fc50b1cc59e26d50940ebf46e1bdcc0ba
This should also get fixed src/primitives/transaction.h: static const uint32_t SEQUENCE_LOCKTIME_DISABLE_FLAG = (1 << 31);
utACK