Running with UBSan throws runtime error regarding bitshift
DanielG opened this issue · comments
When running theft with ubsan enabled (-fsanitize=undefined
) I get the following error:
.src/theft_random.c:79:21: runtime error: shift exponent 64 is too large for 64-bit type 'long unsigned int'
At the mentioned source location we have:
uint8_t shift = 0;
[...]
uint8_t take = 64 - shift;
[...]
t->prng.buf >>= take;
According to the C standard shifting by more than the types size is undefined behaviour:
The behavior is undefined in the following circumstances:
[...]
- An expression is shifted by a negative number or by an amount greater than or equal
to the width of the promoted expression (6.5.7).