Skip to content

Commit cb07ad4

Browse files
committed
cass_result: fix cass_result_first_row
Previous implementation of cass_result_first_row is buggy. It panics when rows are empty. This commit fixes the implementation.
1 parent 7ef61cc commit cb07ad4

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

scylla-rust-wrapper/src/query_result.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1334,11 +1334,12 @@ pub unsafe extern "C" fn cass_result_column_count(result_raw: *const CassResult)
13341334
pub unsafe extern "C" fn cass_result_first_row(result_raw: *const CassResult) -> *const CassRow {
13351335
let result = ptr_to_ref(result_raw);
13361336

1337-
if result.rows.is_some() || result.rows.as_ref().unwrap().is_empty() {
1338-
return result.rows.as_ref().unwrap().first().unwrap();
1339-
}
1340-
1341-
std::ptr::null()
1337+
result
1338+
.rows
1339+
.as_ref()
1340+
.and_then(|rows| rows.first())
1341+
.map(|row| row as *const CassRow)
1342+
.unwrap_or(std::ptr::null())
13421343
}
13431344

13441345
#[no_mangle]

0 commit comments

Comments
 (0)