From ccb6dc90883e10fea556546a4b40332943bb3e87 Mon Sep 17 00:00:00 2001 From: Zakarum Date: Wed, 7 Apr 2021 21:00:40 +0300 Subject: [PATCH] Panic to prevent arena Handle overflow (#667) * Panic to prevent arena Handle overflow * Use `NonZeroU32::new` to detect overflow --- src/arena.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/arena.rs b/src/arena.rs index af3fba55dd..174c79b540 100644 --- a/src/arena.rs +++ b/src/arena.rs @@ -189,7 +189,8 @@ impl Arena { /// Adds a new value to the arena, returning a typed handle. pub fn append(&mut self, value: T) -> Handle { 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) }