@@ -196,7 +196,9 @@ impl TableCollection {
196
196
Err ( e) => return Err ( e) ,
197
197
} ;
198
198
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
+ } ) ?;
200
202
let rv = unsafe {
201
203
ll_bindings:: tsk_table_collection_load (
202
204
tables. as_mut_ptr ( ) ,
@@ -547,7 +549,7 @@ impl TableCollection {
547
549
Some ( unsafe {
548
550
std:: slice:: from_raw_parts (
549
551
( * 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 ( ) ? ,
551
553
)
552
554
} )
553
555
} else {
@@ -563,7 +565,7 @@ impl TableCollection {
563
565
Some ( unsafe {
564
566
std:: slice:: from_raw_parts (
565
567
( * 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 ( ) ? ,
567
569
)
568
570
} )
569
571
} else {
@@ -681,7 +683,9 @@ impl TableCollection {
681
683
/// This function allocates a `CString` to pass the file name to the C API.
682
684
/// A panic will occur if the system runs out of memory.
683
685
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
+ } ) ?;
685
689
let rv = unsafe {
686
690
ll_bindings:: tsk_table_collection_dump (
687
691
self . as_ptr ( ) ,
0 commit comments