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.
This commit is contained in:
parent
846ab858a6
commit
173cbe112c
1 changed files with 2 additions and 2 deletions
|
@ -241,9 +241,9 @@ size_t olm_group_decrypt(
|
||||||
|
|
||||||
/* pick a megolm instance to use. If we're at or beyond the latest ratchet
|
/* pick a megolm instance to use. If we're at or beyond the latest ratchet
|
||||||
* value, use that */
|
* 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;
|
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. */
|
/* the counter is before our intial ratchet - we can't decode this. */
|
||||||
session->last_error = OLM_UNKNOWN_MESSAGE_INDEX;
|
session->last_error = OLM_UNKNOWN_MESSAGE_INDEX;
|
||||||
return (size_t)-1;
|
return (size_t)-1;
|
||||||
|
|
Loading…
Reference in a new issue