]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-112388: Fix an error that was causing the parser to try to overwrite tokeni...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 27 Nov 2023 18:56:27 +0000 (19:56 +0100)
committerGitHub <noreply@github.com>
Mon, 27 Nov 2023 18:56:27 +0000 (18:56 +0000)
gh-112388: Fix an error that was causing the parser to try to overwrite tokenizer errors (GH-112410)
(cherry picked from commit 2c8b19174274c183eb652932871f60570123fe99)

Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Lib/test/test_syntax.py
Misc/NEWS.d/next/Core and Builtins/2023-11-25-22-58-49.gh-issue-112388.MU3cIM.rst [new file with mode: 0644]
Parser/pegen_errors.c

index 07049087cdacc0c551f49a9a7292720e9edf0419..bbd22eccb3e5b1007a9e6cac14d2a941d1aa36d5 100644 (file)
@@ -2152,6 +2152,7 @@ func(
 
     def test_invisible_characters(self):
         self._check_error('print\x17("Hello")', "invalid non-printable character")
+        self._check_error(b"with(0,,):\n\x01", "invalid non-printable character")
 
     def test_match_call_does_not_raise_syntax_error(self):
         code = """
diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-11-25-22-58-49.gh-issue-112388.MU3cIM.rst b/Misc/NEWS.d/next/Core and Builtins/2023-11-25-22-58-49.gh-issue-112388.MU3cIM.rst
new file mode 100644 (file)
index 0000000..1c82be2
--- /dev/null
@@ -0,0 +1,2 @@
+Fix an error that was causing the parser to try to overwrite tokenizer
+errors. Patch by pablo Galindo
index 005356110a434023e0b358e5265bc3158271ebec..29d5a6e179f3075c892096c6fba8e228b0b6ae58 100644 (file)
@@ -212,6 +212,10 @@ exit:
 void *
 _PyPegen_raise_error(Parser *p, PyObject *errtype, const char *errmsg, ...)
 {
+    // Bail out if we already have an error set.
+    if (p->error_indicator && PyErr_Occurred()) {
+        return NULL;
+    }
     if (p->fill == 0) {
         va_list va;
         va_start(va, errmsg);