don't overflow when relations are empty (#18891)
# Objective - Fixes #18890 ## Solution - Don't overflow when substracting, bound at 0 ## Testing - Reproducer from the issue now works
This commit is contained in:
parent
18e1bf1c3d
commit
12f71a8936
@ -213,7 +213,7 @@ impl OrderedRelationshipSourceCollection for Vec<Entity> {
|
||||
|
||||
fn place_most_recent(&mut self, index: usize) {
|
||||
if let Some(entity) = self.pop() {
|
||||
let index = index.min(self.len() - 1);
|
||||
let index = index.min(self.len().saturating_sub(1));
|
||||
self.insert(index, entity);
|
||||
}
|
||||
}
|
||||
@ -221,7 +221,7 @@ impl OrderedRelationshipSourceCollection for Vec<Entity> {
|
||||
fn place(&mut self, entity: Entity, index: usize) {
|
||||
if let Some(current) = <[Entity]>::iter(self).position(|e| *e == entity) {
|
||||
// The len is at least 1, so the subtraction is safe.
|
||||
let index = index.min(self.len() - 1);
|
||||
let index = index.min(self.len().saturating_sub(1));
|
||||
Vec::remove(self, current);
|
||||
self.insert(index, entity);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user