Pad restored local vars to 15 slots

The Quetzal save format only stores the number of local vars the
routine declared, but the runtime indexes local_vars[0..14] for any
variable access. Restored routines had short lists, causing IndexError
on the first command after restore.
This commit is contained in:
Jared Miller 2026-02-10 12:00:15 -05:00
parent 1ee89e5e3c
commit 776cfba021
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C

View file

@ -214,13 +214,16 @@ class QuetzalParser:
evalstack_size = (bytes[ptr] << 8) + bytes[ptr + 1]
ptr += 2
# read anywhere from 0 to 15 local vars
# read anywhere from 0 to 15 local vars, pad to 15
num_locals = flags_bitfield[0:4]
local_vars = []
for _i in range(flags_bitfield[0:4]):
for _i in range(num_locals):
var = (bytes[ptr] << 8) + bytes[ptr + 1]
ptr += 2
local_vars.append(var)
log(f" Found {len(local_vars)} local vars")
# runtime expects 15 slots, save only stores declared count
local_vars.extend([0] * (15 - num_locals))
log(f" Found {num_locals} local vars (padded to 15)")
# least recent to most recent stack values:
stack_values = []