Skip to content

Commit 70cae6a

Browse files
committed
clean up to_bytes
1 parent 08936c4 commit 70cae6a

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

sysvar/src/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,6 @@ pub fn get_sysvar(
263263
match result {
264264
solana_program_entrypoint::SUCCESS => Ok(()),
265265
OFFSET_LENGTH_EXCEEDS_SYSVAR => Err(solana_program_error::ProgramError::InvalidArgument),
266-
SYSVAR_NOT_FOUND => Err(solana_program_error::ProgramError::UnsupportedSysvar),
267-
// Unexpected errors are folded into `UnsupportedSysvar`.
268266
_ => Err(solana_program_error::ProgramError::UnsupportedSysvar),
269267
}
270268
}
@@ -356,15 +354,18 @@ mod tests {
356354

357355
/// Convert a value to its in-memory byte representation.
358356
///
359-
/// Safety: This relies on the type's plain old data layout. Intended for tests.
357+
/// # Safety
358+
///
359+
/// This function is only safe for plain-old-data types with no padding.
360+
/// Intended for test use only.
360361
pub fn to_bytes<T>(value: &T) -> Vec<u8> {
362+
let size = core::mem::size_of::<T>();
363+
let ptr = (value as *const T) as *const u8;
364+
let mut data = vec![0u8; size];
361365
unsafe {
362-
let size = core::mem::size_of::<T>();
363-
let ptr = (value as *const T) as *const u8;
364-
let mut data = vec![0u8; size];
365366
std::ptr::copy_nonoverlapping(ptr, data.as_mut_ptr(), size);
366-
data
367367
}
368+
data
368369
}
369370

370371
#[test]

0 commit comments

Comments
 (0)