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;
1616
1717/// Interpret the bytes in `data` as a value of type `T`
1818pub 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 )
2024}
2125
2226/// Interpret the bytes in `data` as a mutable value of type `T`
2327#[ allow( unused) ]
2428pub 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 )
2634}
2735
2836/// 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-
31use solana_program:: program_error:: ProgramError ;
42use solana_program:: pubkey:: Pubkey ;
53use solana_program:: sysvar:: slot_history:: AccountInfo ;
@@ -44,11 +42,7 @@ pub fn process_instruction(
4442 instruction_data : & [ u8 ] ,
4543 input : * mut u8 ,
4644) -> 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) ?;
5246
5347 if cmd_data. ver_ != PC_VERSION {
5448 //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