Skip to content

Commit

Permalink
cass_result: fix cass_result_first_row
Browse files Browse the repository at this point in the history
Previous implementation of cass_result_first_row
is buggy. It panics when rows are empty.

This commit fixes the implementation.
  • Loading branch information
muzarski committed Oct 7, 2024
1 parent 413e091 commit 54d25a2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions scylla-rust-wrapper/src/query_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1337,11 +1337,12 @@ pub unsafe extern "C" fn cass_result_column_count(result_raw: *const CassResult)
pub unsafe extern "C" fn cass_result_first_row(result_raw: *const CassResult) -> *const CassRow {
let result = ptr_to_ref(result_raw);

if result.rows.is_some() || result.rows.as_ref().unwrap().is_empty() {
return result.rows.as_ref().unwrap().first().unwrap();
}

std::ptr::null()
result
.rows
.as_ref()
.and_then(|rows| rows.first())
.map(|row| row as *const CassRow)
.unwrap_or(std::ptr::null())
}

#[no_mangle]
Expand Down

0 comments on commit 54d25a2

Please sign in to comment.