@@ -480,12 +480,21 @@ where
480
480
context. start_new_block ( BlockKind :: IfThenBranch , remaining_then_length) ;
481
481
} else {
482
482
context. current_block . pc += remaining_then_length;
483
- // Skip over the prolog to the else branch if present
483
+
484
+ /*
485
+ * Skip over the prolog to the else branch if present. Also handle if
486
+ * there are no more bytes to peek - the `If` op could be the last op
487
+ * in a block.
488
+ */
484
489
const DEF_ELSE_OP : u8 = 0xa1 ;
485
- // TODO: maybe need to handle error here
486
- if context. peek ( ) ? == DEF_ELSE_OP {
487
- context. next ( ) ?;
488
- let _else_length = context. pkglength ( ) ?;
490
+ match context. peek ( ) {
491
+ Ok ( DEF_ELSE_OP ) => {
492
+ context. next ( ) ?;
493
+ let _else_length = context. pkglength ( ) ?;
494
+ }
495
+ Ok ( _) => ( ) ,
496
+ Err ( AmlError :: RunOutOfStream ) => ( ) ,
497
+ Err ( other) => Err ( other) ?,
489
498
}
490
499
}
491
500
}
@@ -776,16 +785,24 @@ where
776
785
BlockKind :: IfThenBranch => {
777
786
context. current_block = context. block_stack . pop ( ) . unwrap ( ) ;
778
787
779
- // Check for an else-branch, and skip over it
780
- // TODO: if we run out of stream here, it might just be an IfOp at the
781
- // end I think?
788
+ /*
789
+ * Check for an else-branch, and skip over it. We need to handle the
790
+ * case here where there isn't a next byte - that just means the `If`
791
+ * is the last op in a block.
792
+ */
782
793
const DEF_ELSE_OP : u8 = 0xa1 ;
783
- if context. peek ( ) ? == DEF_ELSE_OP {
784
- context. next ( ) ?;
785
- let start_pc = context. current_block . pc ;
786
- let else_length = context. pkglength ( ) ?;
787
- context. current_block . pc += else_length - ( context. current_block . pc - start_pc) ;
788
- }
794
+ match context. peek ( ) {
795
+ Ok ( DEF_ELSE_OP ) => {
796
+ context. next ( ) ?;
797
+ let start_pc = context. current_block . pc ;
798
+ let else_length = context. pkglength ( ) ?;
799
+ context. current_block . pc +=
800
+ else_length - ( context. current_block . pc - start_pc) ;
801
+ }
802
+ Ok ( _) => ( ) ,
803
+ Err ( AmlError :: RunOutOfStream ) => ( ) ,
804
+ Err ( other) => Err ( other) ?,
805
+ } ;
789
806
790
807
continue ;
791
808
}
0 commit comments