From 82e9652d86cdbfb8fbef80d18f59e79bd7bdae26 Mon Sep 17 00:00:00 2001 From: Taylor Sutton Date: Fri, 1 Apr 2022 17:22:03 -0700 Subject: [PATCH] fix(vm): off-by-one in code block stringification. The call to retrieve operands modifies pc, setting it to the index of the *next* instruction. So, we save its initial value and use that for printing. Acked-by: Taylor Sutton --- boa_engine/src/vm/code_block.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/boa_engine/src/vm/code_block.rs b/boa_engine/src/vm/code_block.rs index 93279870ca0..d7bf07dcdd0 100644 --- a/boa_engine/src/vm/code_block.rs +++ b/boa_engine/src/vm/code_block.rs @@ -351,9 +351,10 @@ impl ToInternedString for CodeBlock { while pc < self.code.len() { let opcode: Opcode = self.code[pc].try_into().expect("invalid opcode"); let opcode = opcode.as_str(); + let previous_pc = pc; let operands = self.instruction_operands(&mut pc, interner); f.push_str(&format!( - "{pc:06} {count:04} {opcode:<27}{operands}\n", + "{previous_pc:06} {count:04} {opcode:<27}{operands}\n", )); count += 1; }