aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2016-05-20 12:40:59 +0100
committerRichard van der Hoff <richard@matrix.org>2016-05-24 13:40:21 +0100
commit173cbe112c139de0bd1a69dce5a03db360dc5abc (patch)
treee48f7f2fc99887d15c42469c16485e9b66d63d6e /src
parent846ab858a6dd2e962d3e110147f4274416026f5a (diff)
Avoid relying on uint -> int casting behaviour
The behaviour when casting from a uint32_t which has overflowed (so has the top bit set) to int32_t is implementation-defined, so let's avoid relying on it.
Diffstat (limited to 'src')
-rw-r--r--src/inbound_group_session.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/inbound_group_session.c b/src/inbound_group_session.c
index cc6ba5e..b8f762d 100644
--- a/src/inbound_group_session.c
+++ b/src/inbound_group_session.c
@@ -241,9 +241,9 @@ size_t olm_group_decrypt(
/* pick a megolm instance to use. If we're at or beyond the latest ratchet
* value, use that */
- if ((int32_t)(decoded_results.message_index - session->latest_ratchet.counter) >= 0) {
+ if ((decoded_results.message_index - session->latest_ratchet.counter) < (1U << 31)) {
megolm = &session->latest_ratchet;
- } else if ((int32_t)(decoded_results.message_index - session->initial_ratchet.counter) < 0) {
+ } else if ((decoded_results.message_index - session->initial_ratchet.counter) >= (1U << 31)) {
/* the counter is before our intial ratchet - we can't decode this. */
session->last_error = OLM_UNKNOWN_MESSAGE_INDEX;
return (size_t)-1;