Skip to content

Commit

Permalink
Disallow references to static mut
Browse files Browse the repository at this point in the history
  • Loading branch information
yogh333 committed Dec 17, 2024
1 parent c07bb11 commit f9f5f25
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
10 changes: 2 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,10 @@ icon = "crab_32x32.gif"

[package.metadata.ledger.flex]
icon = "crab_40x40.gif"

[patch.crates-io]
ledger_device_sdk = { path = "../ledger-device-rust-sdk/ledger_device_sdk" }
include_gif = { path = "../ledger-device-rust-sdk/include_gif" }

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("stax", "flex", "nanos", "nanox", "nanosplus"))'] }
12 changes: 8 additions & 4 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,30 @@ impl Settings {
#[inline(never)]
#[allow(unused)]
pub fn get_mut(&mut self) -> &mut AtomicStorage<[u8; SETTINGS_SIZE]> {
return unsafe { DATA.get_mut() };
let data = &raw mut DATA;
return unsafe { (*data).get_mut() };
}

#[inline(never)]
#[allow(unused)]
pub fn get_ref(&mut self) -> &AtomicStorage<[u8; SETTINGS_SIZE]> {
return unsafe { DATA.get_ref() };
let data = &raw const DATA;
return unsafe { (*data).get_ref() };
}

#[allow(unused)]
pub fn get_element(&self, index: usize) -> u8 {
let storage = unsafe { DATA.get_ref() };
let data = &raw const DATA;
let storage = unsafe { (*data).get_ref() };
let settings = storage.get_ref();
settings[index]
}

#[allow(unused)]
// Not used in this boilerplate, but can be used to set a value in the settings
pub fn set_element(&self, index: usize, value: u8) {
let storage = unsafe { DATA.get_mut() };
let data = &raw mut DATA;
let storage = unsafe { (*data).get_mut() };
let mut updated_data = *storage.get_ref();
updated_data[index] = value;
unsafe {
Expand Down

0 comments on commit f9f5f25

Please sign in to comment.