Skip to content

Commit d66f3d6

Browse files
committed
mark fn unsafe, fix five8 use
1 parent 1b21d13 commit d66f3d6

File tree

2 files changed

+12
-30
lines changed

2 files changed

+12
-30
lines changed

sdk/pinocchio/src/sysvars/slot_hashes/raw.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ pub fn fetch_into(buffer: &mut [u8], offset: usize) -> Result<usize, ProgramErro
6464

6565
validate_fetch_offset(offset, buffer.len())?;
6666

67-
fetch_into_unchecked(buffer, offset)?;
67+
// SAFETY: `buffer.len()` and `offset` are both validated above.
68+
unsafe { fetch_into_unchecked(buffer, offset) }?;
6869

6970
let num_entries = read_entry_count_from_bytes(buffer).unwrap_or(0);
7071

@@ -90,22 +91,15 @@ pub fn fetch_into(buffer: &mut [u8], offset: usize) -> Result<usize, ProgramErro
9091
///
9192
/// # Safety
9293
/// Internally this function performs an unchecked Solana syscall that writes
93-
/// raw bytes into the provided pointer. That call is wrapped in an `unsafe`
94-
/// block with the guarantees listed above.
94+
/// raw bytes into the provided pointer.
9595
#[inline(always)]
96-
pub fn fetch_into_unchecked(buffer: &mut [u8], offset: usize) -> Result<(), ProgramError> {
97-
// SAFETY: `buffer.as_mut_ptr()` is valid for `buffer.len()` bytes and
98-
// writable for the duration of the call. We rely on the caller to have
99-
// ensured that `offset + buffer.len()` does not exceed the real sysvar
100-
// size (`MAX_SIZE`).
101-
unsafe {
102-
crate::sysvars::get_sysvar_unchecked(
103-
buffer.as_mut_ptr(),
104-
&SLOTHASHES_ID,
105-
offset,
106-
buffer.len(),
107-
)
108-
}?;
96+
pub unsafe fn fetch_into_unchecked(buffer: &mut [u8], offset: usize) -> Result<(), ProgramError> {
97+
crate::sysvars::get_sysvar_unchecked(
98+
buffer.as_mut_ptr(),
99+
&SLOTHASHES_ID,
100+
offset,
101+
buffer.len(),
102+
)?;
109103

110104
Ok(())
111105
}

sdk/pinocchio/src/sysvars/slot_hashes/test.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,9 @@ fn test_layout_constants() {
3131
);
3232

3333
pub fn check_base58(input_bytes: &[u8], expected_b58: &str) {
34-
match five8_const::decode_32_const(expected_b58).into_vec() {
35-
Ok(decoded) => {
36-
assert_eq!(
37-
input_bytes,
38-
decoded.as_slice(),
39-
"Base58 decode mismatch: expected {:?}, got {:?}",
40-
input_bytes,
41-
decoded
42-
);
43-
}
44-
Err(e) => {
45-
panic!("Failed to decode base58 string '{}': {}", expected_b58, e);
46-
}
47-
}
34+
assert_eq!(five8_const::decode_32_const(expected_b58), input_bytes);
4835
}
36+
4937
check_base58(
5038
&SLOTHASHES_ID,
5139
"SysvarS1otHashes111111111111111111111111111",

0 commit comments

Comments
 (0)