-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
don't overflow when relations are empty #18891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -213,15 +213,15 @@ 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); | |||
} | |||
} | |||
|
|||
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment suggests the - 1
should always be safe, so does it indicate something else wrong?
Noting that I approve of the change to saturating_sub
generally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line here IMO cannot fail, as the position
call cannot return Some
if there are no items to filter.
The bugfix is thus in the other line that was changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok that makes sense. This line was just changed while he was here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense!
# Objective - Fixes #18890 ## Solution - Don't overflow when substracting, bound at 0 ## Testing - Reproducer from the issue now works
# Objective - Fixes bevyengine#18890 ## Solution - Don't overflow when substracting, bound at 0 ## Testing - Reproducer from the issue now works
Objective
EntityWorldMut::insert_children
panics on index 0 #18890Solution
Testing