Skip to content

Commit 06fba36

Browse files
committed
MutTxId: fix oops and UB
1 parent 9d949f4 commit 06fba36

File tree

1 file changed

+6
-14
lines changed
  • crates/core/src/db/datastore/locking_tx_datastore

1 file changed

+6
-14
lines changed

crates/core/src/db/datastore/locking_tx_datastore/mut_tx.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,21 +1572,13 @@ impl MutTxId {
15721572
let tx_row_ref = unsafe { tx_table.get_row_ref_unchecked(tx_blob_store, tx_row_ptr) };
15731573

15741574
let err = 'error: {
1575-
// These two macros can be thought of as a `throw $e` and `$e?` within `'error`.
1575+
// This macros can be thought of as a `throw $e` within `'error`.
15761576
// TODO(centril): Get rid of this once we have stable `try` blocks or polonius.
15771577
macro_rules! throw {
15781578
($e:expr) => {
15791579
break 'error $e.into()
15801580
};
15811581
}
1582-
macro_rules! unwrap {
1583-
($e:expr) => {
1584-
match $e {
1585-
Ok(x) => x,
1586-
Err(e) => throw!(e),
1587-
}
1588-
};
1589-
}
15901582

15911583
// Check that the index exists and is unique.
15921584
// It's sufficient to check the committed state.
@@ -1618,15 +1610,16 @@ impl MutTxId {
16181610
};
16191611
// SAFETY: `commit_table.row_layout() == new_row.row_layout()` holds
16201612
// as the `tx_table` is derived from `commit_table`.
1621-
unwrap!(unsafe {
1613+
if let Err(e) = unsafe {
16221614
commit_table.check_unique_constraints(
16231615
tx_row_ref,
16241616
// Don't check this index since we'll do a 1-1 old/new replacement.
16251617
|ixs| ixs.filter(|(&id, _)| id != index_id),
16261618
is_deleted,
16271619
)
1620+
} {
1621+
throw!(IndexError::from(e));
16281622
}
1629-
.map_err(IndexError::from));
16301623

16311624
let tx_row_ptr = if let Some(old_ptr) = commit_old_ptr {
16321625
// Row was found in the committed state!
@@ -1660,7 +1653,7 @@ impl MutTxId {
16601653
// in particular, the `write_gen_val_to_col` call does not remove the row.
16611654
// On error, `tx_row_ptr` has already been removed, so don't do it again.
16621655
let (_, tx_row_ptr) =
1663-
unwrap!(unsafe { tx_table.confirm_insertion::<false>(tx_blob_store, tx_row_ptr, blob_bytes) });
1656+
unsafe { tx_table.confirm_insertion::<false>(tx_blob_store, tx_row_ptr, blob_bytes) }?;
16641657

16651658
// Delete the old row.
16661659
del_table.insert(old_ptr);
@@ -1678,8 +1671,7 @@ impl MutTxId {
16781671
// SAFETY: `tx_table.is_row_present(tx_row_ptr)` and `tx_table.is_row_present(old_ptr)` both hold
16791672
// as we've deleted neither.
16801673
// In particular, the `write_gen_val_to_col` call does not remove the row.
1681-
let tx_row_ptr =
1682-
unwrap!(unsafe { tx_table.confirm_update(tx_blob_store, tx_row_ptr, old_ptr, blob_bytes) });
1674+
let tx_row_ptr = unsafe { tx_table.confirm_update(tx_blob_store, tx_row_ptr, old_ptr, blob_bytes) }?;
16831675

16841676
if let Some(old_commit_del_ptr) = old_commit_del_ptr {
16851677
// If we have an identical deleted row in the committed state,

0 commit comments

Comments
 (0)