From 4d2dadd3acd9dc25f0feae865b74cbaea7250f3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Rodr=C3=ADguez?= Date: Thu, 8 Jun 2023 16:01:55 +0200 Subject: [PATCH] fix(brillig): expand memory with zeroes on store (#350) --- brillig_vm/src/lib.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/brillig_vm/src/lib.rs b/brillig_vm/src/lib.rs index c9373e52a..4d7e6cac2 100644 --- a/brillig_vm/src/lib.rs +++ b/brillig_vm/src/lib.rs @@ -223,9 +223,15 @@ impl VM { } Opcode::Store { destination_pointer, source: source_register } => { // Convert our destination_pointer to a usize - let destination = self.registers.get(*destination_pointer); + let destination = self.registers.get(*destination_pointer).to_usize(); + if destination >= self.memory.len() { + self.memory.append(&mut vec![ + Value::from(0_usize); + destination - self.memory.len() + 1 + ]); + } // Use our usize destination index to set the value in memory - self.memory[destination.to_usize()] = self.registers.get(*source_register); + self.memory[destination] = self.registers.get(*source_register); self.increment_program_counter() } Opcode::Call { location } => {