Skip to content

Commit

Permalink
Fix issue 26287: While handling FORMAT_VALUE opcode, the top of stack…
Browse files Browse the repository at this point in the history
… was being corrupted if an error occurred in PyObject_Format().
  • Loading branch information
ericvsmith committed Feb 5, 2016
1 parent a3643c2 commit 135d5f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions Lib/test/test_fstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,17 @@ def test_invalid_expressions(self):
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))
Expand Down
4 changes: 2 additions & 2 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -3383,7 +3383,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
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) {
Expand Down Expand Up @@ -3426,7 +3426,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
goto error;
}

SET_TOP(result);
PUSH(result);
DISPATCH();
}

Expand Down

0 comments on commit 135d5f4

Please sign in to comment.