diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2024-02-26 12:57:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-26 12:57:09 (GMT) |
commit | 015b97d19a24a169cc3c0939119e1228791e4253 (patch) | |
tree | 5111a5aeb6566145cd725cd7928eb0d031e71bc6 /Parser | |
parent | b7383b8b71d49c761480ae9a8b2111644310e61d (diff) | |
download | cpython-015b97d19a24a169cc3c0939119e1228791e4253.zip cpython-015b97d19a24a169cc3c0939119e1228791e4253.tar.gz cpython-015b97d19a24a169cc3c0939119e1228791e4253.tar.bz2 |
gh-115823: Calculate correctly error locations when dealing with implicit encodings (#115824)
Diffstat (limited to 'Parser')
-rw-r--r-- | Parser/pegen_errors.c | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/Parser/pegen_errors.c b/Parser/pegen_errors.c index e15673d..e8f11a6 100644 --- a/Parser/pegen_errors.c +++ b/Parser/pegen_errors.c @@ -369,20 +369,18 @@ _PyPegen_raise_error_known_location(Parser *p, PyObject *errtype, Py_ssize_t col_number = col_offset; Py_ssize_t end_col_number = end_col_offset; - if (p->tok->encoding != NULL) { - col_number = _PyPegen_byte_offset_to_character_offset(error_line, col_offset); - if (col_number < 0) { + col_number = _PyPegen_byte_offset_to_character_offset(error_line, col_offset); + if (col_number < 0) { + goto error; + } + + if (end_col_offset > 0) { + end_col_number = _PyPegen_byte_offset_to_character_offset(error_line, end_col_offset); + if (end_col_number < 0) { goto error; } - if (end_col_number > 0) { - Py_ssize_t end_col_offset = _PyPegen_byte_offset_to_character_offset(error_line, end_col_number); - if (end_col_offset < 0) { - goto error; - } else { - end_col_number = end_col_offset; - } - } } + tmp = Py_BuildValue("(OnnNnn)", p->tok->filename, lineno, col_number, error_line, end_lineno, end_col_number); if (!tmp) { goto error; |