diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2021-11-20 17:40:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-20 17:40:59 (GMT) |
commit | 79ff0d1687e3f823fb121a19f0297ad052871b1b (patch) | |
tree | 174a9ebeccda6a91cb0fec2aa2cc09dcc803d88c /Parser | |
parent | 48744db70ed519c1566c22bf123a0e1f5c69253f (diff) | |
download | cpython-79ff0d1687e3f823fb121a19f0297ad052871b1b.zip cpython-79ff0d1687e3f823fb121a19f0297ad052871b1b.tar.gz cpython-79ff0d1687e3f823fb121a19f0297ad052871b1b.tar.bz2 |
bpo-45494: Fix error location in EOF tokenizer errors (GH-29108)
Diffstat (limited to 'Parser')
-rw-r--r-- | Parser/pegen.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Parser/pegen.c b/Parser/pegen.c index b3fdae4..b760730 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -382,8 +382,12 @@ _PyPegen_raise_error(Parser *p, PyObject *errtype, const char *errmsg, ...) Py_ssize_t col_offset; Py_ssize_t end_col_offset = -1; if (t->col_offset == -1) { - col_offset = Py_SAFE_DOWNCAST(p->tok->cur - p->tok->buf, - intptr_t, int); + if (p->tok->cur == p->tok->buf) { + col_offset = 0; + } else { + const char* start = p->tok->buf ? p->tok->line_start : p->tok->buf; + col_offset = Py_SAFE_DOWNCAST(p->tok->cur - start, intptr_t, int); + } } else { col_offset = t->col_offset + 1; } @@ -410,6 +414,7 @@ get_error_line(Parser *p, Py_ssize_t lineno) assert(p->tok->fp == NULL || p->tok->fp == stdin); char *cur_line = p->tok->fp_interactive ? p->tok->interactive_src_start : p->tok->str; + assert(cur_line != NULL); for (int i = 0; i < lineno - 1; i++) { cur_line = strchr(cur_line, '\n') + 1; |