diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2021-11-16 19:51:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-16 19:51:52 (GMT) |
commit | df4ae55e66e34ea8de6a34f0b104871ddaf35d53 (patch) | |
tree | 9559446a2a5a37add62c564a99ee496bf5d3843b /Parser | |
parent | 9d6215a54c177a5e359c37ecd1c50b594b194f41 (diff) | |
download | cpython-df4ae55e66e34ea8de6a34f0b104871ddaf35d53.zip cpython-df4ae55e66e34ea8de6a34f0b104871ddaf35d53.tar.gz cpython-df4ae55e66e34ea8de6a34f0b104871ddaf35d53.tar.bz2 |
bpo-45820: Fix a segfault when the parser fails without reading any input (GH-29580)
Diffstat (limited to 'Parser')
-rw-r--r-- | Parser/pegen.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Parser/pegen.c b/Parser/pegen.c index 8a3f740..2931a40 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -368,6 +368,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, 0, -1, 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; Py_ssize_t end_col_offset = -1; |