- 
                Notifications
    
You must be signed in to change notification settings  - Fork 13
 
Closed
Labels
P1P1 priority item - very importantP1 priority item - very importantgood first issueGood for newcomersGood for newcomers
Milestone
Description
Currently, we assume that user uses the API correctly, and we panic if the provided pointer is null.
Example:
#[unsafe(no_mangle)]
pub unsafe extern "C" fn cass_cluster_set_connect_timeout(
    cluster_raw: CassBorrowedExclusivePtr<CassCluster, CMut>,
    timeout_ms: c_uint,
) {
    let cluster = BoxFFI::as_mut_ref(cluster_raw).unwrap();
    cluster.session_builder.config.connect_timeout = Duration::from_millis(timeout_ms.into());
}This unwrap() panics if cluster_raw is null.
This should be converted to something like:
#[unsafe(no_mangle)]
pub unsafe extern "C" fn cass_cluster_set_connect_timeout(
    cluster_raw: CassBorrowedExclusivePtr<CassCluster, CMut>,
    timeout_ms: c_uint,
) {
    let Some(cluster) = BoxFFI::as_mut_ref(cluster_raw) else {
        tracing::error!("Provided null pointer to cass_cluster_set_connect_timeout!");
        return CassError::CASS_ERROR_LIB_BAD_PARAMS;
    };
    cluster.session_builder.config.connect_timeout = Duration::from_millis(timeout_ms.into());
}wprzytula
Metadata
Metadata
Assignees
Labels
P1P1 priority item - very importantP1 priority item - very importantgood first issueGood for newcomersGood for newcomers