File tree Expand file tree Collapse file tree 2 files changed +11
-9
lines changed Expand file tree Collapse file tree 2 files changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -16,13 +16,21 @@ use solana_program::program_error::ProgramError;
16
16
17
17
/// Interpret the bytes in `data` as a value of type `T`
18
18
pub fn load < T : Pod > ( data : & [ u8 ] ) -> Result < & T , ProgramError > {
19
- try_from_bytes ( & data[ 0 ..size_of :: < T > ( ) ] ) . map_err ( |_| ProgramError :: InvalidArgument )
19
+ try_from_bytes (
20
+ data. get ( 0 ..size_of :: < T > ( ) )
21
+ . ok_or ( ProgramError :: InvalidArgument ) ?,
22
+ )
23
+ . map_err ( |_| ProgramError :: InvalidArgument )
20
24
}
21
25
22
26
/// Interpret the bytes in `data` as a mutable value of type `T`
23
27
#[ allow( unused) ]
24
28
pub fn load_mut < T : Pod > ( data : & mut [ u8 ] ) -> Result < & mut T , ProgramError > {
25
- try_from_bytes_mut ( & mut data[ 0 ..size_of :: < T > ( ) ] ) . map_err ( |_| ProgramError :: InvalidArgument )
29
+ try_from_bytes_mut (
30
+ data. get_mut ( 0 ..size_of :: < T > ( ) )
31
+ . ok_or ( ProgramError :: InvalidArgument ) ?,
32
+ )
33
+ . map_err ( |_| ProgramError :: InvalidArgument )
26
34
}
27
35
28
36
/// Get the data stored in `account` as a value of type `T`
Original file line number Diff line number Diff line change 1
- use std:: mem:: size_of;
2
-
3
1
use solana_program:: program_error:: ProgramError ;
4
2
use solana_program:: pubkey:: Pubkey ;
5
3
use solana_program:: sysvar:: slot_history:: AccountInfo ;
@@ -44,11 +42,7 @@ pub fn process_instruction(
44
42
instruction_data : & [ u8 ] ,
45
43
input : * mut u8 ,
46
44
) -> OracleResult {
47
- let cmd_hdr_size = size_of :: < cmd_hdr > ( ) ;
48
- if instruction_data. len ( ) < cmd_hdr_size {
49
- return Err ( ProgramError :: InvalidArgument ) ;
50
- }
51
- let cmd_data = load :: < cmd_hdr > ( & instruction_data[ ..cmd_hdr_size] ) ?;
45
+ let cmd_data = load :: < cmd_hdr > ( instruction_data) ?;
52
46
53
47
if cmd_data. ver_ != PC_VERSION {
54
48
//FIXME: I am not sure what's best to do here (this is copied from C)
You can’t perform that action at this time.
0 commit comments