Skip to content

Commit ddb1090

Browse files
fix: inventory slot bounds check (#900)
## Summary - prevent panic when mutating invalid inventory slots ## Testing - `cargo fmt --all -- --check` *(fails: could not download toolchain)* - `cargo test --locked --all --no-run` *(fails: could not download toolchain)* --------- Co-authored-by: TestingPlant <44930139+TestingPlant@users.noreply.github.com>
1 parent 2e3e0d4 commit ddb1090

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

  • crates/hyperion-inventory/src

crates/hyperion-inventory/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,9 @@ impl Inventory {
326326
&mut self,
327327
index: u16,
328328
) -> Result<&mut ItemSlot, InventoryAccessError> {
329-
let index = usize::from(index);
330-
let slot = &mut self.slots[index];
331-
Ok(slot)
329+
self.slots
330+
.get_mut(usize::from(index))
331+
.ok_or(InventoryAccessError::InvalidSlot { index })
332332
}
333333

334334
/// Returns remaining [`ItemStack`] if not all of the item was added to the slot

0 commit comments

Comments
 (0)