-
Notifications
You must be signed in to change notification settings - Fork 12
Don't panic when null pointer is provided - log error and return instead #300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This was introduced before we had `borrow()` method on pointer types. We can now remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Phew! This was one of the most boring PRs to review ;P
cluster_raw: CassBorrowedExclusivePtr<CassCluster, CMut>, | ||
enable: cass_bool_t, | ||
) -> CassError { | ||
let cluster = BoxFFI::as_mut_ref(cluster_raw).unwrap(); | ||
let Some(cluster) = BoxFFI::as_mut_ref(cluster_raw) else { | ||
tracing::error!( | ||
"Provided null cluster pointer to cass_cluster_set_use_beta_protocol_version!" | ||
); | ||
return CassError::CASS_ERROR_LIB_BAD_PARAMS; | ||
}; | ||
|
||
cluster.use_beta_protocol_version = enable == cass_true; | ||
|
||
CassError::CASS_OK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Does cass_cluster_set_use_beta_protocol_version()
do anything? AFAIK Rust driver supports just one protocol version, so this is a no-op. Shouldn't we rather mark this as deprecated and/or remove its implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is read here:
#[unsafe(no_mangle)]
pub unsafe extern "C" fn cass_cluster_set_protocol_version(
cluster_raw: CassBorrowedExclusivePtr<CassCluster, CMut>,
protocol_version: c_int,
) -> CassError {
let Some(cluster) = BoxFFI::as_mut_ref(cluster_raw) else {
tracing::error!("Provided null cluster pointer to cass_cluster_set_protocol_version!");
return CassError::CASS_ERROR_LIB_BAD_PARAMS;
};
if protocol_version == 4 && !cluster.use_beta_protocol_version {
// Rust Driver supports only protocol version 4
CassError::CASS_OK
} else {
CassError::CASS_ERROR_LIB_BAD_PARAMS
}
}
Fixes: #253
Pre-review checklist
[ ] I have implemented Rust unit tests for the features/changes introduced.[ ] I have enabled appropriate tests in.github/workflows/build.yml
ingtest_filter
.[ ] I have enabled appropriate tests in.github/workflows/cassandra.yml
ingtest_filter
.