@@ -196,7 +196,9 @@ impl TableCollection {
196196 Err ( e) => return Err ( e) ,
197197 } ;
198198
199- let c_str = std:: ffi:: CString :: new ( filename. as_ref ( ) ) . unwrap ( ) ;
199+ let c_str = std:: ffi:: CString :: new ( filename. as_ref ( ) ) . map_err ( |_| {
200+ TskitError :: LibraryError ( "call to ffi::CString::new failed" . to_string ( ) )
201+ } ) ?;
200202 let rv = unsafe {
201203 ll_bindings:: tsk_table_collection_load (
202204 tables. as_mut_ptr ( ) ,
@@ -547,7 +549,7 @@ impl TableCollection {
547549 Some ( unsafe {
548550 std:: slice:: from_raw_parts (
549551 ( * self . as_ptr ( ) ) . indexes . edge_insertion_order as * const EdgeId ,
550- usize:: try_from ( ( * self . as_ptr ( ) ) . indexes . num_edges ) . unwrap ( ) ,
552+ usize:: try_from ( ( * self . as_ptr ( ) ) . indexes . num_edges ) . ok ( ) ? ,
551553 )
552554 } )
553555 } else {
@@ -563,7 +565,7 @@ impl TableCollection {
563565 Some ( unsafe {
564566 std:: slice:: from_raw_parts (
565567 ( * self . as_ptr ( ) ) . indexes . edge_removal_order as * const EdgeId ,
566- usize:: try_from ( ( * self . as_ptr ( ) ) . indexes . num_edges ) . unwrap ( ) ,
568+ usize:: try_from ( ( * self . as_ptr ( ) ) . indexes . num_edges ) . ok ( ) ? ,
567569 )
568570 } )
569571 } else {
@@ -681,7 +683,9 @@ impl TableCollection {
681683 /// This function allocates a `CString` to pass the file name to the C API.
682684 /// A panic will occur if the system runs out of memory.
683685 pub fn dump < O : Into < TableOutputOptions > > ( & self , filename : & str , options : O ) -> TskReturnValue {
684- let c_str = std:: ffi:: CString :: new ( filename) . unwrap ( ) ;
686+ let c_str = std:: ffi:: CString :: new ( filename) . map_err ( |_| {
687+ TskitError :: LibraryError ( "call to ffi::CString::new failed" . to_string ( ) )
688+ } ) ?;
685689 let rv = unsafe {
686690 ll_bindings:: tsk_table_collection_dump (
687691 self . as_ptr ( ) ,
0 commit comments