[Python-checkins] cpython: Fix issue 26287: While handling FORMAT_VALUE opcode, the top of stack was being

eric.smith python-checkins at python.org
Fri Feb 5 18:23:13 EST 2016


https://hg.python.org/cpython/rev/9095a5787a82
changeset:   100165:9095a5787a82
parent:      100162:d3be5c4507b4
user:        Eric V. Smith <eric at trueblade.com>
date:        Fri Feb 05 18:23:08 2016 -0500
summary:
  Fix issue 26287: While handling FORMAT_VALUE opcode, the top of stack was being corrupted if an error occurred in PyObject_Format().

files:
  Lib/test/test_fstring.py |  11 +++++++++++
  Python/ceval.c           |   4 ++--
  2 files changed, 13 insertions(+), 2 deletions(-)


diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py
--- a/Lib/test/test_fstring.py
+++ b/Lib/test/test_fstring.py
@@ -692,6 +692,17 @@
                              r"f'{a(4]}'",
                             ])
 
+    def test_errors(self):
+        # see issue 26287
+        self.assertAllRaise(TypeError, 'non-empty',
+                            [r"f'{(lambda: 0):x}'",
+                             r"f'{(0,):x}'",
+                             ])
+        self.assertAllRaise(ValueError, 'Unknown format code',
+                            [r"f'{1000:j}'",
+                             r"f'{1000:j}'",
+                            ])
+
     def test_loop(self):
         for i in range(1000):
             self.assertEqual(f'i:{i}', 'i:' + str(i))
diff --git a/Python/ceval.c b/Python/ceval.c
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -3383,7 +3383,7 @@
             int have_fmt_spec = (oparg & FVS_MASK) == FVS_HAVE_SPEC;
 
             fmt_spec = have_fmt_spec ? POP() : NULL;
-            value = TOP();
+            value = POP();
 
             /* See if any conversion is specified. */
             switch (which_conversion) {
@@ -3426,7 +3426,7 @@
                     goto error;
             }
 
-            SET_TOP(result);
+            PUSH(result);
             DISPATCH();
         }
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list