summaryrefslogtreecommitdiff
path: root/tools/mpy-tool.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2019-09-02 13:30:16 +1000
committerDamien George <damien.p.george@gmail.com>2019-09-02 13:30:16 +1000
commitb29fae0c564bae271f3659563a2a61230dab5def (patch)
treec3df636b7dbbd7dc60a2df33302cb50e5618c8d3 /tools/mpy-tool.py
parentc348e791879e8615347403f541717eb9386fe4ee (diff)
py/bc: Fix size calculation of UNWIND_JUMP opcode in mp_opcode_format.
Prior to this patch mp_opcode_format would calculate the incorrect size of the MP_BC_UNWIND_JUMP opcode, missing the additional byte. But, because opcodes below 0x10 are unused and treated as bytes in the .mpy load/save and freezing code, this bug did not show any symptoms, since nested unwind jumps would rarely (if ever) reach a depth of 16 (so the extra byte of this opcode would be between 0x01 and 0x0f and be correctly loaded/saved/frozen simply as an undefined opcode). This patch fixes this bug by correctly accounting for the additional byte. .
Diffstat (limited to 'tools/mpy-tool.py')
-rwxr-xr-xtools/mpy-tool.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py
index 3d2a8fb7c..e5c8f0959 100755
--- a/tools/mpy-tool.py
+++ b/tools/mpy-tool.py
@@ -109,6 +109,7 @@ MP_OPCODE_VAR_UINT = 2
MP_OPCODE_OFFSET = 3
# extra bytes:
+MP_BC_UNWIND_JUMP = 0x46
MP_BC_MAKE_CLOSURE = 0x62
MP_BC_MAKE_CLOSURE_DEFARGS = 0x63
MP_BC_RAISE_VARARGS = 0x5c
@@ -215,7 +216,8 @@ def mp_opcode_format(bytecode, ip, count_var_uint, opcode_format=make_opcode_for
ip += 3
else:
extra_byte = (
- opcode == MP_BC_RAISE_VARARGS
+ opcode == MP_BC_UNWIND_JUMP
+ or opcode == MP_BC_RAISE_VARARGS
or opcode == MP_BC_MAKE_CLOSURE
or opcode == MP_BC_MAKE_CLOSURE_DEFARGS
)