Skip to content

Commit

Permalink
AML: Fix UnexpectedEndOfStream in DefIfElse in terminal position
Browse files Browse the repository at this point in the history
  • Loading branch information
alnyan authored and IsaacWoods committed Aug 28, 2023
1 parent 0e15346 commit bec70c4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions aml/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ where
* Predicate := TermArg => Integer (0 = false, >0 = true)
* DefElse := Nothing | <0xa1 PkgLength TermList>
*/

let maybe_else_opcode = |input, context| match opcode(opcode::DEF_ELSE_OP).parse(input, context) {
Err((x, y, Propagate::Err(AmlError::UnexpectedEndOfStream))) => {
Err((x, y, Propagate::Err(AmlError::WrongParser)))
}
r => r,
};

opcode(opcode::DEF_IF_ELSE_OP)
.then(comment_scope(
DebugVerbosity::Scopes,
Expand All @@ -135,11 +143,11 @@ where
.map(move |then_branch| Ok((predicate_arg.as_bool()?, then_branch)))
})
.then(choice!(
opcode(opcode::DEF_ELSE_OP)
maybe_else_opcode
.then(comment_scope(
DebugVerbosity::AllScopes,
"DefElse",
pkg_length().feed(|length| take_to_end_of_pkglength(length))
pkg_length().feed(|length| take_to_end_of_pkglength(length)),
))
.map(|((), else_branch): ((), &[u8])| Ok(else_branch)),
// TODO: can this be `id().map(&[])`?
Expand Down

0 comments on commit bec70c4

Please sign in to comment.