diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-11-18 00:24:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-18 00:24:43 (GMT) |
commit | 00ee14e814d35587ac55f89c7de871a01360c876 (patch) | |
tree | 9166e3239b6052200cc868ddb7b8266ef9ba05a0 /Parser | |
parent | 0ef308a2890571c850c624fb99ac00f8951363c6 (diff) | |
download | cpython-00ee14e814d35587ac55f89c7de871a01360c876.zip cpython-00ee14e814d35587ac55f89c7de871a01360c876.tar.gz cpython-00ee14e814d35587ac55f89c7de871a01360c876.tar.bz2 |
[3.9] bpo-45820: Fix a segfault when the parser fails without reading any input (GH-29580) (GH-29584)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Co-authored-by: Ćukasz Langa <lukasz@langa.pl>
Diffstat (limited to 'Parser')
-rw-r--r-- | Parser/pegen/pegen.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Parser/pegen/pegen.c b/Parser/pegen/pegen.c index 2e986c5..cdfbc12 100644 --- a/Parser/pegen/pegen.c +++ b/Parser/pegen/pegen.c @@ -364,6 +364,14 @@ tokenizer_error(Parser *p) void * _PyPegen_raise_error(Parser *p, PyObject *errtype, const char *errmsg, ...) { + if (p->fill == 0) { + va_list va; + va_start(va, errmsg); + _PyPegen_raise_error_known_location(p, errtype, 0, 0, errmsg, va); + va_end(va); + return NULL; + } + Token *t = p->known_err_token != NULL ? p->known_err_token : p->tokens[p->fill - 1]; Py_ssize_t col_offset; if (t->col_offset == -1) { |