Skip to content

Commit

Permalink
Panic if bit_count > 32
Browse files Browse the repository at this point in the history
  • Loading branch information
9names committed May 28, 2024
1 parent e2caa1c commit de8fecf
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,21 @@ impl InstructionOperands {
*index | (if *relative { 0b10000 } else { 0 }),
)
}
InstructionOperands::IN { source, bit_count } => (*source as u8, *bit_count & 0b11111),
InstructionOperands::IN { source, bit_count } => {
if *bit_count > 32 {
panic!("bit_count must be from 1 to 32");
}
(*source as u8, *bit_count & 0b11111)
}
InstructionOperands::OUT {
destination,
bit_count,
} => (*destination as u8, *bit_count & 0b11111),
} => {
if *bit_count > 32 {
panic!("bit_count must be from 1 to 32");
}
(*destination as u8, *bit_count & 0b11111)
}
InstructionOperands::PUSH { if_full, block } => {
((*if_full as u8) << 1 | (*block as u8), 0)
}
Expand Down

0 comments on commit de8fecf

Please sign in to comment.