Skip to content

Commit

Permalink
Merge pull request #417 from vectordotdev/fix-null-rebalance
Browse files Browse the repository at this point in the history
Fix handling of NULL pointer in `NativeClient::rebalance_protocol`
  • Loading branch information
benesch authored Dec 30, 2021
2 parents bbd3417 + de421ba commit 7a2355f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,17 @@ impl NativeClient {
}

pub(crate) fn rebalance_protocol(&self) -> RebalanceProtocol {
let protocol = unsafe { CStr::from_ptr(rdsys::rd_kafka_rebalance_protocol(self.ptr())) };
match protocol.to_bytes() {
b"NONE" => RebalanceProtocol::None,
b"EAGER" => RebalanceProtocol::Eager,
b"COOPERATIVE" => RebalanceProtocol::Cooperative,
_ => unreachable!(),
let protocol = unsafe { rdsys::rd_kafka_rebalance_protocol(self.ptr()) };
if protocol.is_null() {
RebalanceProtocol::None
} else {
let protocol = unsafe { CStr::from_ptr(protocol) };
match protocol.to_bytes() {
b"NONE" => RebalanceProtocol::None,
b"EAGER" => RebalanceProtocol::Eager,
b"COOPERATIVE" => RebalanceProtocol::Cooperative,
_ => unreachable!(),
}
}
}
}
Expand Down

0 comments on commit 7a2355f

Please sign in to comment.