Skip to content

Commit

Permalink
clippy: missing_transmute_annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
yihau committed May 14, 2024
1 parent 44f6cbd commit 01b5fe5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
8 changes: 6 additions & 2 deletions program-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,12 @@ thread_local! {
static INVOKE_CONTEXT: RefCell<Option<usize>> = const { RefCell::new(None) };
}
fn set_invoke_context(new: &mut InvokeContext) {
INVOKE_CONTEXT
.with(|invoke_context| unsafe { invoke_context.replace(Some(transmute::<_, usize>(new))) });
INVOKE_CONTEXT.with(|invoke_context| unsafe {
invoke_context.replace(Some(transmute::<
&mut solana_program_runtime::invoke_context::InvokeContext<'_>,
usize,
>(new)))
});
}
fn get_invoke_context<'a, 'b>() -> &'a mut InvokeContext<'b> {
let ptr = INVOKE_CONTEXT.with(|invoke_context| match *invoke_context.borrow() {
Expand Down
11 changes: 10 additions & 1 deletion programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,16 @@ fn execute<'a, 'b: 'a>(
) -> Result<(), Box<dyn std::error::Error>> {
// We dropped the lifetime tracking in the Executor by setting it to 'static,
// thus we need to reintroduce the correct lifetime of InvokeContext here again.
let executable = unsafe { mem::transmute::<_, &'a Executable<InvokeContext<'b>>>(executable) };
let executable = unsafe {
mem::transmute::<
&solana_rbpf::elf::Executable<
solana_program_runtime::invoke_context::InvokeContext<'_>,
>,
&solana_rbpf::elf::Executable<
solana_program_runtime::invoke_context::InvokeContext<'_>,
>,
>(executable)
};
let log_collector = invoke_context.get_log_collector();
let transaction_context = &invoke_context.transaction_context;
let instruction_context = transaction_context.get_current_instruction_context()?;
Expand Down
12 changes: 10 additions & 2 deletions programs/loader-v4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,16 @@ fn execute<'a, 'b: 'a>(
) -> Result<(), Box<dyn std::error::Error>> {
// We dropped the lifetime tracking in the Executor by setting it to 'static,
// thus we need to reintroduce the correct lifetime of InvokeContext here again.
let executable =
unsafe { std::mem::transmute::<_, &'a Executable<InvokeContext<'b>>>(executable) };
let executable = unsafe {
std::mem::transmute::<
&solana_rbpf::elf::Executable<
solana_program_runtime::invoke_context::InvokeContext<'_>,
>,
&solana_rbpf::elf::Executable<
solana_program_runtime::invoke_context::InvokeContext<'_>,
>,
>(executable)
};
let log_collector = invoke_context.get_log_collector();
let stack_height = invoke_context.get_stack_height();
let transaction_context = &invoke_context.transaction_context;
Expand Down
2 changes: 1 addition & 1 deletion programs/sbf/rust/invoke/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ fn process_instruction(
let mut lamports = account.lamports();
account
.lamports
.replace(unsafe { mem::transmute(&mut lamports) });
.replace(unsafe { mem::transmute::<&mut u64, &mut u64>(&mut lamports) });
let callee_program_id = accounts[CALLEE_PROGRAM_INDEX].key;

invoke(
Expand Down
8 changes: 6 additions & 2 deletions unified-scheduler-logic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,12 @@ mod utils {
#[cfg_attr(miri, ignore)]
fn test_ub_illegally_created_multiple_tokens() {
// Unauthorized token minting!
let mut token1 = unsafe { mem::transmute(()) };
let mut token2 = unsafe { mem::transmute(()) };
let mut token1 = unsafe {
mem::transmute::<(), crate::utils::Token<crate::utils::tests::FakeQueue>>(())
};
let mut token2 = unsafe {
mem::transmute::<(), crate::utils::Token<crate::utils::tests::FakeQueue>>(())
};

let queue = TokenCell::new(FakeQueue {
v: Vec::with_capacity(20),
Expand Down

0 comments on commit 01b5fe5

Please sign in to comment.