From aecc704f9c8992b8cee3e8776c9c999fa8936c3c Mon Sep 17 00:00:00 2001 From: "Kevin R. Thornton" Date: Fri, 28 Oct 2022 16:09:27 -0700 Subject: [PATCH] refactor: remove unwraps from node_table.rs --- src/node_table.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/node_table.rs b/src/node_table.rs index d6c281ff5..eb901d22d 100644 --- a/src/node_table.rs +++ b/src/node_table.rs @@ -109,21 +109,33 @@ impl<'a> NodeTable<'a> { } /// Mutable access to node flags. + /// + /// # Note + /// + /// Internally, we rely on a conversion of u64 to usize. + /// This conversion is fallible on some platforms. + /// If the conversion fails, an empty slice is returned. pub fn flags_array_mut(&mut self) -> &mut [NodeFlags] { unsafe { std::slice::from_raw_parts_mut( self.table_.flags.cast::(), - usize::try_from(self.table_.num_rows).unwrap(), + usize::try_from(self.table_.num_rows).unwrap_or(0), ) } } /// Mutable access to node times. + /// + /// # Note + /// + /// Internally, we rely on a conversion of u64 to usize. + /// This conversion is fallible on some platforms. + /// If the conversion fails, an empty slice is returned. pub fn time_array_mut(&mut self) -> &mut [Time] { unsafe { std::slice::from_raw_parts_mut( self.table_.time.cast::