Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if argument of SET instructions is valid #64

Merged
merged 2 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading