From eba64d2afb4c429e80d863dc0dd7808bdbef30d3 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Salgado Date: Thu, 4 May 2023 15:15:26 +0100 Subject: [PATCH] gh-104169: Ensure the tokenizer doesn't overwrite previous errors (#104170) --- Parser/tokenizer.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 7c07d2011fd..52d0d9a534c 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -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) {