diff options
author | Richard van der Hoff <richard@matrix.org> | 2016-05-24 17:52:35 +0100 |
---|---|---|
committer | Richard van der Hoff <richard@matrix.org> | 2016-05-24 17:52:35 +0100 |
commit | 01ea3d4b9a3c6f3e0303c2d421a248715a96af99 (patch) | |
tree | 553ba1b809d0cc44e96e3860cee28f9aac4f4802 /src | |
parent | 1f31427139acdef00f24aac13b67224fa915f9e7 (diff) |
Fix handling of integer wraparound in megolm.c
Diffstat (limited to 'src')
-rw-r--r-- | src/megolm.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/megolm.c b/src/megolm.c index 6d8af08..a969b36 100644 --- a/src/megolm.c +++ b/src/megolm.c @@ -108,8 +108,12 @@ void megolm_advance_to(Megolm *megolm, uint32_t advance_to) { uint32_t mask = (~(uint32_t)0) << shift; int k; - /* how many times to we need to rehash this part? */ - int steps = (advance_to >> shift) - (megolm->counter >> shift); + /* how many times do we need to rehash this part? + * + * '& 0xff' ensures we handle integer wraparound correctly + */ + unsigned int steps = + ((advance_to >> shift) - (megolm->counter >> shift)) & 0xff; if (steps == 0) { continue; |