Skip to content

Commit d69cbd0

Browse files
committed
Fix review comments
1 parent 094036b commit d69cbd0

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

interface/src/instruction.rs

+3
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,9 @@ pub enum TokenInstruction {
491491
///
492492
/// Both the number of accounts and instruction data length are used to identify
493493
/// the slice of accounts and instruction data for each instruction.
494+
///
495+
/// Note that it is not sound to have a `batch` instruction that contains other
496+
/// `batch` instruction; an error will be raised when this is detected.
494497
Batch = 255,
495498
// Any new variants also need to be added to program-2022 `TokenInstruction`, so that the
496499
// latter remains a superset of this instruction set. New variants also need to be added to

p-token/src/processor/batch.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn process_batch(mut accounts: &[AccountInfo], mut instruction_data: &[u8])
2323
let expected_accounts = unsafe { *instruction_data.get_unchecked(0) as usize };
2424
let data_offset = IX_HEADER_SIZE + unsafe { *instruction_data.get_unchecked(1) as usize };
2525

26-
if instruction_data.len() < data_offset || data_offset == 0 {
26+
if instruction_data.len() < data_offset || data_offset == IX_HEADER_SIZE {
2727
return Err(ProgramError::InvalidInstructionData);
2828
}
2929

@@ -34,13 +34,15 @@ pub fn process_batch(mut accounts: &[AccountInfo], mut instruction_data: &[u8])
3434
// Process the instruction.
3535

3636
// SAFETY: The instruction data and accounts lengths are already validated so all
37-
// the slices are guaranteed to be valid.
38-
unsafe {
39-
inner_process_instruction(
37+
// slices are guaranteed to be valid.
38+
let (ix_accounts, ix_data) = unsafe {
39+
(
4040
accounts.get_unchecked(..expected_accounts),
4141
instruction_data.get_unchecked(IX_HEADER_SIZE..data_offset),
42-
)?;
43-
}
42+
)
43+
};
44+
45+
inner_process_instruction(ix_accounts, ix_data)?;
4446

4547
if data_offset == instruction_data.len() {
4648
// The batch is complete.

0 commit comments

Comments
 (0)