Skip to content

Commit

Permalink
Merge pull request #64 from jannic/check-set-argument
Browse files Browse the repository at this point in the history
Check if argument of SET instructions is valid
  • Loading branch information
jannic authored Sep 15, 2024
2 parents 9c9317d + 2ceffff commit 60fd8a5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 8 additions & 1 deletion pio-parser/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// PIO instr grouping is 3/5/3/5
#![allow(clippy::manual_range_contains)]
#![allow(clippy::unusual_byte_groupings)]
#![allow(clippy::upper_case_acronyms)]

Expand Down Expand Up @@ -189,7 +190,13 @@ impl<'i> ParsedOperands<'i> {
},
ParsedOperands::SET { destination, data } => InstructionOperands::SET {
destination: *destination,
data: data.reify(state) as u8,
data: {
let arg = data.reify(state);
if arg < 0 || arg > 0x1f {
panic!("SET argument out of range: {}", arg);
}
arg as u8
},
},
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,12 @@ impl InstructionOperands {
*index | (if *relative { 0b10000 } else { 0 }),
)
}
InstructionOperands::SET { destination, data } => (*destination as u8, *data),
InstructionOperands::SET { destination, data } => {
if *data > 0x1f {
panic!("SET argument out of range");
}
(*destination as u8, *data)
}
}
}

Expand Down

0 comments on commit 60fd8a5

Please sign in to comment.