diff options
author | Damien George <damien.p.george@gmail.com> | 2019-09-02 13:30:16 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2019-09-02 13:30:16 +1000 |
commit | b29fae0c564bae271f3659563a2a61230dab5def (patch) | |
tree | c3df636b7dbbd7dc60a2df33302cb50e5618c8d3 /py/bc.c | |
parent | c348e791879e8615347403f541717eb9386fe4ee (diff) | |
download | micropython-b29fae0c564bae271f3659563a2a61230dab5def.tar.gz micropython-b29fae0c564bae271f3659563a2a61230dab5def.zip |
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 'py/bc.c')
-rw-r--r-- | py/bc.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -292,7 +292,8 @@ continue2:; #if MICROPY_PERSISTENT_CODE_LOAD || MICROPY_PERSISTENT_CODE_SAVE // The following table encodes the number of bytes that a specific opcode -// takes up. There are 3 special opcodes that always have an extra byte: +// takes up. There are 4 special opcodes that always have an extra byte: +// MP_BC_UNWIND_JUMP // MP_BC_MAKE_CLOSURE // MP_BC_MAKE_CLOSURE_DEFARGS // MP_BC_RAISE_VARARGS @@ -402,7 +403,8 @@ uint mp_opcode_format(const byte *ip, size_t *opcode_size, bool count_var_uint) ip += 3; } else { int extra_byte = ( - *ip == MP_BC_RAISE_VARARGS + *ip == MP_BC_UNWIND_JUMP + || *ip == MP_BC_RAISE_VARARGS || *ip == MP_BC_MAKE_CLOSURE || *ip == MP_BC_MAKE_CLOSURE_DEFARGS ); |