diff --git a/crates/matrix-sdk/src/event_cache/linked_chunk.rs b/crates/matrix-sdk/src/event_cache/linked_chunk.rs index 0630d8b81..f73df70f6 100644 --- a/crates/matrix-sdk/src/event_cache/linked_chunk.rs +++ b/crates/matrix-sdk/src/event_cache/linked_chunk.rs @@ -593,15 +593,14 @@ impl ChunkIdentifierGenerator { /// In this case, `Result::Err` contains the previous unique identifier. pub fn generate_next(&self) -> Result { let previous = self.next.fetch_add(1, Ordering::Relaxed); - let current = self.next.load(Ordering::Relaxed); // Check for overflows. // unlikely — TODO: call `std::intrinsics::unlikely` once it's stable. - if current < previous { + if previous == u64::MAX { return Err(ChunkIdentifier(previous)); } - Ok(ChunkIdentifier(current)) + Ok(ChunkIdentifier(previous.saturating_add(1))) } }