Panic to prevent arena Handle overflow (#667)

* Panic to prevent arena Handle overflow

* Use `NonZeroU32::new` to detect overflow
This commit is contained in:
Zakarum authored and GitHub committed 2021-04-07 14:00:40 -04:00
1 parent 0058ce5a7d
commit ccb6dc9088
1 file changed
+2 -1
+2 -1
View File
@@ -189,7 +189,8 @@ impl<T> Arena<T> {
/// Adds a new value to the arena, returning a typed handle.
pub fn append(&mut self, value: T) -> Handle<T> {
let position = self.data.len() + 1;
let index = unsafe { Index::new_unchecked(position as u32) };
let index =
Index::new(position as u32).expect("Failed to append to Arena. Handle overflows");
self.data.push(value);
Handle::new(index)
}