fix(core): fix up clippy warnings in storage.rs
What changed, and why it matters
This is a tiny code cleanup commit that replaces two calls to `ptr::null()` with Rust's `unwrap_or_default()` to silence automated Clippy lint warnings. It does not change what value is produced (still a null pointer when no salt is provided) and has no functional or security effect.
No action required. Treat as routine code hygiene.
Security signals we found
No strong security signals were identified.
Evidence from the diff
In core/embed/rust/src/trezorhal/storage.rs, the diff changes salt.map(|s| s.as_ptr()).unwrap_or(ptr::null()) to salt.map(|s| s.as_ptr()).unwrap_or_default() in unlock(), and the same pattern in change_pin(). For Option<&T>, unwrap_or_default() on the mapped *const _ pointer returns ptr::null() because raw pointers implement Default as null. Therefore the generated code and behavior are identical; this is purely a lint-driven refactor.
Changed components
core/embed/rust/src/trezorhal/storage.rsInspect captured patch +2 / −2
diff --git a/core/embed/rust/src/trezorhal/storage.rs b/core/embed/rust/src/trezorhal/storage.rs
index abe8aff4..cf65e062 100644
--- a/core/embed/rust/src/trezorhal/storage.rs
+++ b/core/embed/rust/src/trezorhal/storage.rs
@@ -128,7 +128,7 @@ pub fn lock() {
/// Unlock storage with PIN and optional external salt.
/// Returns true if the PIN + salt combination is correct.
pub fn unlock(pin: &str, salt: Option<&ExternalSalt>) -> bool {
- let salt = salt.map(|s| s.as_ptr()).unwrap_or(ptr::null());
+ let salt = salt.map(|s| s.as_ptr()).unwrap_or_default();
let result = unsafe { ffi::storage_unlock(pin.as_ptr() as *const _, pin.len(), salt) };
matches!(result, ffi::storage_unlock_result_t::UNLOCK_OK)
}
@@ -141,7 +141,7 @@ pub fn change_pin(new_pin: &str, new_salt: Option<&ExternalSalt>) -> bool {
ffi::storage_change_pin(
new_pin.as_ptr() as *const _,
new_pin.len(),
- new_salt.map(|s| s.as_ptr()).unwrap_or(ptr::null()),
+ new_salt.map(|s| s.as_ptr()).unwrap_or_default(),
)
};
matches!(result, ffi::storage_pin_change_result_t::PIN_CHANGE_OK)
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.