Skip to content

Commit

Permalink
Use uninit byte (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
febo authored Dec 30, 2024
1 parent bda7ae4 commit cf4f661
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions sdk/pinocchio/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ pub fn set_return_data(data: &[u8]) {
pub fn get_return_data() -> Option<ReturnData> {
#[cfg(target_os = "solana")]
{
let mut data = [0u8; MAX_RETURN_DATA];
const UNINIT_BYTE: core::mem::MaybeUninit<u8> = core::mem::MaybeUninit::<u8>::uninit();
let mut data = [UNINIT_BYTE; MAX_RETURN_DATA];
let mut program_id = Pubkey::default();

let size = unsafe {
Expand Down Expand Up @@ -311,7 +312,7 @@ pub struct ReturnData {
program_id: Pubkey,

/// Return data set by the program.
data: [u8; MAX_RETURN_DATA],
data: [core::mem::MaybeUninit<u8>; MAX_RETURN_DATA],

/// Length of the return data.
size: usize,
Expand All @@ -325,7 +326,7 @@ impl ReturnData {

/// Return the data set by the program.
pub fn as_slice(&self) -> &[u8] {
&self.data[..self.size]
unsafe { core::slice::from_raw_parts(self.data.as_ptr() as _, self.size) }
}
}

Expand Down

0 comments on commit cf4f661

Please sign in to comment.