[3.12] gh-115823: Calculate correctly error locations when dealing with implicit encodings (GH-115824) (#115949)

gh-115823: Calculate correctly error locations when dealing with implicit encodings (GH-115824)
(cherry picked from commit 015b97d19a)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-02-26 14:18:06 +01:00 committed by GitHub
parent 8668b3cc2d
commit 1932da0c3d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 11 deletions

View file

@ -367,20 +367,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;