summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2021-11-09 22:05:30 (GMT)
committerGitHub <noreply@github.com>2021-11-09 22:05:30 (GMT)
commitc5bfb88eb6f82111bb1603ae9d78d0476b552d66 (patch)
tree1f82414eb63aef1ea2739415ef9869e2ccc2e827 /Lib
parentd29f591dd6b1dcd4f36b5b49761cf8225be690bd (diff)
downloadcpython-c5bfb88eb6f82111bb1603ae9d78d0476b552d66.zip
cpython-c5bfb88eb6f82111bb1603ae9d78d0476b552d66.tar.gz
cpython-c5bfb88eb6f82111bb1603ae9d78d0476b552d66.tar.bz2
[3.10] bpo-45757: Fix bug where dis produced an incorrect oparg on EXTENDED_ARG before a no-arg opcode (GH-29480) (GH-29506)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/dis.py1
-rw-r--r--Lib/test/test_dis.py21
2 files changed, 22 insertions, 0 deletions
diff --git a/Lib/dis.py b/Lib/dis.py
index 3fee1ce..fe5d24e 100644
--- a/Lib/dis.py
+++ b/Lib/dis.py
@@ -428,6 +428,7 @@ def _unpack_opargs(code):
extended_arg = (arg << 8) if op == EXTENDED_ARG else 0
else:
arg = None
+ extended_arg = 0
yield (i, op, arg)
def findlabels(code):
diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index 2cb2eff..000549f 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -180,6 +180,23 @@ dis_bug42562 = """\
2 RETURN_VALUE
"""
+# Extended arg followed by NOP
+code_bug_45757 = bytes([
+ 0x90, 0x01, # EXTENDED_ARG 0x01
+ 0x09, 0xFF, # NOP 0xFF
+ 0x90, 0x01, # EXTENDED_ARG 0x01
+ 0x64, 0x29, # LOAD_CONST 0x29
+ 0x53, 0x00, # RETURN_VALUE 0x00
+ ])
+
+dis_bug_45757 = """\
+ 0 EXTENDED_ARG 1
+ 2 NOP
+ 4 EXTENDED_ARG 1
+ 6 LOAD_CONST 297 (297)
+ 8 RETURN_VALUE
+"""
+
_BIG_LINENO_FORMAT = """\
%3d 0 LOAD_GLOBAL 0 (spam)
2 POP_TOP
@@ -534,6 +551,10 @@ class DisTests(unittest.TestCase):
def test_bug_42562(self):
self.do_disassembly_test(bug42562, dis_bug42562)
+ def test_bug_45757(self):
+ # Extended arg followed by NOP
+ self.do_disassembly_test(code_bug_45757, dis_bug_45757)
+
def test_big_linenos(self):
def func(count):
namespace = {}