Skip to content

Commit f30fbe7

Browse files
committed
remove panic from C invalid-argument callbacks
1 parent 4ae0e7e commit f30fbe7

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

secp256k1-sys/src/lib.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ pub unsafe fn secp256k1_context_destroy(ctx: *mut Context) {
580580
///
581581
/// A callback function to be called when an illegal argument is passed to
582582
/// an API call. It will only trigger for violations that are mentioned
583-
/// explicitly in the header. **This will cause a panic**.
583+
/// explicitly in the header.
584584
///
585585
/// The philosophy is that these shouldn't be dealt with through a
586586
/// specific return value, as calling code should not have branches to deal with
@@ -600,13 +600,14 @@ pub unsafe extern "C" fn rustsecp256k1_v0_4_0_default_illegal_callback_fn(messag
600600
use core::str;
601601
let msg_slice = slice::from_raw_parts(message as *const u8, strlen(message));
602602
let msg = str::from_utf8_unchecked(msg_slice);
603-
panic!("[libsecp256k1] illegal argument. {}", msg);
603+
#[cfg(feature = "std")]
604+
println!("[libsecp256k1] illegal argument. {}", msg);
604605
}
605606

606607
/// **This function is an override for the C function, this is the an edited version of the original description:**
607608
///
608609
/// A callback function to be called when an internal consistency check
609-
/// fails. **This will cause a panic**.
610+
/// fails.
610611
///
611612
/// This can only trigger in case of a hardware failure, miscompilation,
612613
/// memory corruption, serious bug in the library, or other error would can
@@ -623,7 +624,8 @@ pub unsafe extern "C" fn rustsecp256k1_v0_4_0_default_error_callback_fn(message:
623624
use core::str;
624625
let msg_slice = slice::from_raw_parts(message as *const u8, strlen(message));
625626
let msg = str::from_utf8_unchecked(msg_slice);
626-
panic!("[libsecp256k1] internal consistency check failed {}", msg);
627+
#[cfg(feature = "std")]
628+
println!("[libsecp256k1] internal consistency check failed {}", msg);
627629
}
628630

629631
#[cfg(not(rust_secp_no_symbol_renaming))]

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ mod tests {
938938

939939
#[cfg(not(target_arch = "wasm32"))]
940940
#[test]
941-
#[should_panic]
941+
#[should_panic(expected = "assertion failed")]
942942
fn test_panic_raw_ctx() {
943943
let ctx_vrfy = Secp256k1::verification_only();
944944
let raw_ctx_verify_as_full = unsafe {Secp256k1::from_raw_all(ctx_vrfy.ctx)};

0 commit comments

Comments
 (0)