Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/btree/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,25 @@ pub enum BtreeError {
KeyNotFound,

/// A `sqlite_master` entry names a rootpage number outside the valid page range.
///
/// `name` is leaked (via [`Box::leak`]) rather than owned as a `String`:
/// this is a cold, rare corruption-detection path, and leaking here keeps
/// `BtreeError` itself free of drop glue (`needs_drop::<BtreeError>() ==
/// false`), which matters because it is constructed on the hot
/// `TableCursor::seek` path (see #679).
InvalidRootPage {
/// Name of the offending `sqlite_master` entry.
name: String,
name: &'static str,
/// Out-of-range rootpage value.
rootpage: i64,
},

/// A delete targeted a `sqlite_master` entry that does not exist.
///
/// `name` is leaked for the same reason as [`BtreeError::InvalidRootPage`].
MasterEntryNotFound {
/// Name of the entry that could not be found.
name: String,
name: &'static str,
},

/// An internal invariant was violated; the message describes what was expected.
Expand Down Expand Up @@ -369,17 +377,14 @@ mod tests {
);
assert_eq!(
BtreeError::InvalidRootPage {
name: "t".to_string(),
name: "t",
rootpage: -1
}
.to_string(),
"sqlite_master entry \"t\" has out-of-range rootpage -1"
);
assert_eq!(
BtreeError::MasterEntryNotFound {
name: "t".to_string()
}
.to_string(),
BtreeError::MasterEntryNotFound { name: "t" }.to_string(),
"cannot delete sqlite_master entry \"t\": no such entry"
);
assert_eq!(
Expand Down
6 changes: 3 additions & 3 deletions src/btree/master.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub fn delete_master_row(
header.text_encoding,
)?
.ok_or_else(|| BtreeError::MasterEntryNotFound {
name: name.to_string(),
name: Box::leak(name.to_string().into_boxed_str()),
})?;
super::delete_row(pager, header, SQLITE_MASTER_ROOT_PAGE, rowid)
}
Expand Down Expand Up @@ -225,12 +225,12 @@ fn find_master_rootpage(
if let (Some(Value::Text(n)), Some(Value::Integer(rp))) = (values.get(1), values.get(3)) {
if n.as_ref() == name {
let rootpage = u32::try_from(*rp).map_err(|_| BtreeError::InvalidRootPage {
name: name.to_string(),
name: Box::leak(name.to_string().into_boxed_str()),
rootpage: *rp,
})?;
if rootpage == 0 {
return Err(BtreeError::InvalidRootPage {
name: name.to_string(),
name: Box::leak(name.to_string().into_boxed_str()),
rootpage: *rp,
});
}
Expand Down
Loading