Skip to content

Commit 0cd93a2

Browse files
authored
Merge pull request #3578 from Hywan/fix-sdk-linked-chunk-substract-overflow
fix(sdk): Fix a substract with overflow in `LinkedChunk`
2 parents a6c962b + edcd573 commit 0cd93a2

File tree

1 file changed

+17
-1
lines changed
  • crates/matrix-sdk/src/event_cache/linked_chunk

1 file changed

+17
-1
lines changed

crates/matrix-sdk/src/event_cache/linked_chunk/mod.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ impl<const CAPACITY: usize, Item, Gap> Chunk<CAPACITY, Item, Gap> {
10291029

10301030
match &self.content {
10311031
ChunkContent::Gap(..) => Position(identifier, 0),
1032-
ChunkContent::Items(items) => Position(identifier, items.len() - 1),
1032+
ChunkContent::Items(items) => Position(identifier, items.len().saturating_sub(1)),
10331033
}
10341034
}
10351035

@@ -1606,6 +1606,14 @@ mod tests {
16061606
assert_matches!(iterator.next(), None);
16071607
}
16081608

1609+
#[test]
1610+
fn test_ritems_empty() {
1611+
let linked_chunk = LinkedChunk::<2, char, ()>::new();
1612+
let mut iterator = linked_chunk.ritems();
1613+
1614+
assert_matches!(iterator.next(), None);
1615+
}
1616+
16091617
#[test]
16101618
fn test_items() {
16111619
let mut linked_chunk = LinkedChunk::<2, char, ()>::new();
@@ -1623,6 +1631,14 @@ mod tests {
16231631
assert_matches!(iterator.next(), None);
16241632
}
16251633

1634+
#[test]
1635+
fn test_items_empty() {
1636+
let linked_chunk = LinkedChunk::<2, char, ()>::new();
1637+
let mut iterator = linked_chunk.items();
1638+
1639+
assert_matches!(iterator.next(), None);
1640+
}
1641+
16261642
#[test]
16271643
fn test_ritems_from() -> Result<(), Error> {
16281644
let mut linked_chunk = LinkedChunk::<2, char, ()>::new();

0 commit comments

Comments
 (0)