]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40904: Fix segfault in the new parser with f-string containing yield statements...
authorPablo Galindo <Pablogsal@gmail.com>
Mon, 8 Jun 2020 00:47:37 +0000 (01:47 +0100)
committerGitHub <noreply@github.com>
Mon, 8 Jun 2020 00:47:37 +0000 (01:47 +0100)
Lib/test/test_fstring.py
Misc/NEWS.d/next/Core and Builtins/2020-06-08-01-08-57.bpo-40904.76qQzo.rst [new file with mode: 0644]
Parser/pegen/parse_string.c

index ea4e589929e7ec04a73ab3e2d2ddc3b8bf7622a1..9048e89689df25fdccf755176d2b693d4f4010e1 100644 (file)
@@ -725,9 +725,11 @@ non-important content
         #  a function into a generator
         def fn(y):
             f'y:{yield y*2}'
+            f'{yield}'
 
         g = fn(4)
         self.assertEqual(next(g), 8)
+        self.assertEqual(next(g), None)
 
     def test_yield_send(self):
         def fn(x):
diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-08-01-08-57.bpo-40904.76qQzo.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-08-01-08-57.bpo-40904.76qQzo.rst
new file mode 100644 (file)
index 0000000..09009b1
--- /dev/null
@@ -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
index efe82df47658bdb4ad1b8d1c5d476b6cf3fd65f8..94241e1965e9a8e01c2c33fe91efb5bdcf1fcaa2 100644 (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) {
+    if (n == NULL) {
+        return;
+    }
     if (parent->lineno < n->lineno) {
         col = 0;
     }