bpo-40904: Fix segfault in the new parser with f-string containing yield statements with no value (GH-20701)

This commit is contained in:
Pablo Galindo 2020-06-08 01:47:37 +01:00 committed by GitHub
parent bcb198385d
commit 972ab03276
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 0 deletions

View File

@ -725,9 +725,11 @@ non-important content
# a function into a generator # a function into a generator
def fn(y): def fn(y):
f'y:{yield y*2}' f'y:{yield y*2}'
f'{yield}'
g = fn(4) g = fn(4)
self.assertEqual(next(g), 8) self.assertEqual(next(g), 8)
self.assertEqual(next(g), None)
def test_yield_send(self): def test_yield_send(self):
def fn(x): def fn(x):

View File

@ -0,0 +1,2 @@
Fix possible segfault in the new PEG parser when parsing f-string containing
yield statements with no value (:code:`f"{yield}"`). Patch by Pablo Galindo

View File

@ -278,6 +278,9 @@ static void fstring_shift_argument(expr_ty parent, arg_ty args, int lineno, int
static inline void shift_expr(expr_ty parent, expr_ty n, int line, int col) { static inline void shift_expr(expr_ty parent, expr_ty n, int line, int col) {
if (n == NULL) {
return;
}
if (parent->lineno < n->lineno) { if (parent->lineno < n->lineno) {
col = 0; col = 0;
} }