Skip to content

Commit e7de3ef

Browse files
committed
bpo-45820: Fix a segfault when the parser fails without reading any input
1 parent 9bf2cbc commit e7de3ef

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a segfault when the parser fails without reading any input. Patch by
2+
Pablo Galindo

Parser/pegen.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,14 @@ tokenizer_error(Parser *p)
368368
void *
369369
_PyPegen_raise_error(Parser *p, PyObject *errtype, const char *errmsg, ...)
370370
{
371+
if (p->fill == 0) {
372+
va_list va;
373+
va_start(va, errmsg);
374+
_PyPegen_raise_error_known_location(p, errtype, 0, 0, 0, -1, errmsg, va);
375+
va_end(va);
376+
return NULL;
377+
}
378+
371379
Token *t = p->known_err_token != NULL ? p->known_err_token : p->tokens[p->fill - 1];
372380
Py_ssize_t col_offset;
373381
Py_ssize_t end_col_offset = -1;

0 commit comments

Comments
 (0)