diff --git a/openssl/src/stack.rs b/openssl/src/stack.rs index e48ebe77..368b6e07 100644 --- a/openssl/src/stack.rs +++ b/openssl/src/stack.rs @@ -142,31 +142,28 @@ impl Ref> { /// Returns a reference to the element at the given index in the /// stack or `None` if the index is out of bounds pub fn get(&self, idx: usize) -> Option<&Ref> { - if idx >= self.len() { - return None; - } - unsafe { - let r = Ref::from_ptr(self._get(idx)); + if idx >= self.len() { + return None; + } - Some(r) + Some(Ref::from_ptr(self._get(idx))) } } /// Returns a mutable reference to the element at the given index in the /// stack or `None` if the index is out of bounds pub fn get_mut(&mut self, idx: usize) -> Option<&mut Ref> { - if idx >= self.len() { - return None; - } - unsafe { + if idx >= self.len() { + return None; + } + Some(Ref::from_ptr_mut(self._get(idx))) } } unsafe fn _get(&self, idx: usize) -> *mut T::CType { - assert!(idx <= c_int::max_value() as usize); OPENSSL_sk_value(self.as_stack(), idx as c_int) as *mut _ } }