Skip to content

Commit bec70c4

Browse files
alnyanIsaacWoods
authored andcommitted
AML: Fix UnexpectedEndOfStream in DefIfElse in terminal position
1 parent 0e15346 commit bec70c4

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

aml/src/statement.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ where
124124
* Predicate := TermArg => Integer (0 = false, >0 = true)
125125
* DefElse := Nothing | <0xa1 PkgLength TermList>
126126
*/
127+
128+
let maybe_else_opcode = |input, context| match opcode(opcode::DEF_ELSE_OP).parse(input, context) {
129+
Err((x, y, Propagate::Err(AmlError::UnexpectedEndOfStream))) => {
130+
Err((x, y, Propagate::Err(AmlError::WrongParser)))
131+
}
132+
r => r,
133+
};
134+
127135
opcode(opcode::DEF_IF_ELSE_OP)
128136
.then(comment_scope(
129137
DebugVerbosity::Scopes,
@@ -135,11 +143,11 @@ where
135143
.map(move |then_branch| Ok((predicate_arg.as_bool()?, then_branch)))
136144
})
137145
.then(choice!(
138-
opcode(opcode::DEF_ELSE_OP)
146+
maybe_else_opcode
139147
.then(comment_scope(
140148
DebugVerbosity::AllScopes,
141149
"DefElse",
142-
pkg_length().feed(|length| take_to_end_of_pkglength(length))
150+
pkg_length().feed(|length| take_to_end_of_pkglength(length)),
143151
))
144152
.map(|((), else_branch): ((), &[u8])| Ok(else_branch)),
145153
// TODO: can this be `id().map(&[])`?

0 commit comments

Comments
 (0)