Skip to content

Commit 62011b2

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 0c998a1 commit 62011b2

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

scylla-rust-wrapper/src/query_result.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,11 +1337,12 @@ pub unsafe extern "C" fn cass_result_column_count(result_raw: *const CassResult)
13371337
pub unsafe extern "C" fn cass_result_first_row(result_raw: *const CassResult) -> *const CassRow {
13381338
let result = ptr_to_ref(result_raw);
13391339

1340-
if result.rows.is_some() || result.rows.as_ref().unwrap().is_empty() {
1341-
return result.rows.as_ref().unwrap().first().unwrap();
1342-
}
1343-
1344-
std::ptr::null()
1340+
result
1341+
.rows
1342+
.as_ref()
1343+
.and_then(|rows| rows.first())
1344+
.map(|row| row as *const CassRow)
1345+
.unwrap_or(std::ptr::null())
13451346
}
13461347

13471348
#[no_mangle]

0 commit comments

Comments
 (0)