File tree Expand file tree Collapse file tree 2 files changed +19
-9
lines changed Expand file tree Collapse file tree 2 files changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -303,10 +303,9 @@ impl TryFrom<SizeType> for tsk_id_t {
303
303
type Error = crate :: TskitError ;
304
304
305
305
fn try_from ( value : SizeType ) -> Result < Self , Self :: Error > {
306
- if value. 0 > tsk_id_t:: MAX as tsk_size_t {
307
- Err ( TskitError :: RangeError ( stringify ! ( value. 0 ) . to_string ( ) ) )
308
- } else {
309
- Ok ( value. 0 as tsk_id_t )
306
+ match tsk_id_t:: try_from ( value. 0 ) {
307
+ Ok ( v) => Ok ( v) ,
308
+ Err ( _) => Err ( TskitError :: RangeError ( stringify ! ( value. 0 ) . to_string ( ) ) ) ,
310
309
}
311
310
}
312
311
}
Original file line number Diff line number Diff line change @@ -711,10 +711,12 @@ impl<'a> PostorderNodeIterator<'a> {
711
711
let mut num_nodes_current_tree: usize = 0 ;
712
712
let ptr = std:: ptr:: addr_of_mut!( num_nodes_current_tree) ;
713
713
let mut nodes = vec ! [
714
- NodeId :: NULL ;
715
- // NOTE: this fn does not return error codes
716
- crate :: util:: handle_u64_to_usize( unsafe { ll_bindings:: tsk_tree_get_size_bound( tree. as_ptr( ) ) } )
717
- ] ;
714
+ NodeId :: NULL ;
715
+ // NOTE: this fn does not return error codes
716
+ crate :: util:: handle_u64_to_usize( unsafe {
717
+ ll_bindings:: tsk_tree_get_size_bound( tree. as_ptr( ) )
718
+ } )
719
+ ] ;
718
720
719
721
let rv = unsafe {
720
722
ll_bindings:: tsk_tree_postorder (
@@ -838,7 +840,16 @@ struct ParentsIterator<'a> {
838
840
839
841
impl < ' a > ParentsIterator < ' a > {
840
842
fn new ( tree : & ' a Tree , u : NodeId ) -> Result < Self , TskitError > {
841
- match u. 0 >= tree. num_nodes as tsk_id_t {
843
+ let num_nodes = match tsk_id_t:: try_from ( tree. num_nodes ) {
844
+ Ok ( n) => n,
845
+ Err ( _) => {
846
+ return Err ( TskitError :: RangeError ( format ! (
847
+ "could not convert {} into tsk_id_t" ,
848
+ stringify!( num_nodes)
849
+ ) ) )
850
+ }
851
+ } ;
852
+ match u. 0 >= num_nodes {
842
853
true => Err ( TskitError :: IndexError ) ,
843
854
false => Ok ( ParentsIterator {
844
855
current_node : None ,
You can’t perform that action at this time.
0 commit comments