]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-104169: Ensure the tokenizer doesn't overwrite previous errors (#104170)
authorPablo Galindo Salgado <Pablogsal@gmail.com>
Thu, 4 May 2023 14:15:26 +0000 (15:15 +0100)
committerGitHub <noreply@github.com>
Thu, 4 May 2023 14:15:26 +0000 (15:15 +0100)
Parser/tokenizer.c

index 7c07d2011fda616a4965384a06e0f451b27279ff..52d0d9a534cb6a8531d859bc1ca1d0aa7623a173 100644 (file)
@@ -1277,6 +1277,12 @@ _syntaxerror_range(struct tok_state *tok, const char *format,
                    int col_offset, int end_col_offset,
                    va_list vargs)
 {
+    // In release builds, we don't want to overwrite a previous error, but in debug builds we
+    // want to fail if we are not doing it so we can fix it.
+    assert(tok->done != E_ERROR);
+    if (tok->done == E_ERROR) {
+        return ERRORTOKEN;
+    }
     PyObject *errmsg, *errtext, *args;
     errmsg = PyUnicode_FromFormatV(format, vargs);
     if (!errmsg) {