Skip to content

Commit

Permalink
Fix UBSan error: Shifting 64 bit type by 64 is undefined behaviour
Browse files Browse the repository at this point in the history
Shifting a type by >=sizeof(type)*8 is undefined behaviour in C. Since
t->prng.buf is overwritten on the next iteration anyways this thankfully
isn't a real bug here.

Fixes silentbicycle#52
  • Loading branch information
DanielG committed Dec 18, 2019
1 parent 62e093d commit d4f4a02
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/theft_random.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ void theft_random_bits_bulk(struct theft *t, uint32_t bit_count, uint64_t *buf)
LOG(5, "== buf[%zd]: %016" PRIx64 " (%u / %u)\n",
offset, buf[offset], bit_count - rem, bit_count);
t->prng.bits_available -= take;
t->prng.buf >>= take;

if(take < 64)
t->prng.buf >>= take;

shift += take;
if (shift == 64) {
Expand Down

0 comments on commit d4f4a02

Please sign in to comment.