summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorBatuhan Taskaya <isidentical@gmail.com>2022-11-12 23:37:25 (GMT)
committerGitHub <noreply@github.com>2022-11-12 23:37:25 (GMT)
commit57be5459593bbd09583317ebdafc4d58ae51dbf4 (patch)
treeb730c61cc81558a94898b1ffb603a5b42210fd26 /Python
parentc95f554a408f76f96c14c006ebe8a0d3d3b40765 (diff)
downloadcpython-57be5459593bbd09583317ebdafc4d58ae51dbf4.zip
cpython-57be5459593bbd09583317ebdafc4d58ae51dbf4.tar.gz
cpython-57be5459593bbd09583317ebdafc4d58ae51dbf4.tar.bz2
gh-99103: Normalize specialized traceback anchors against the current line (GH-99145)
Automerge-Triggered-By: GH:isidentical
Diffstat (limited to 'Python')
-rw-r--r--Python/traceback.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/Python/traceback.c b/Python/traceback.c
index aacdb33..356e643 100644
--- a/Python/traceback.c
+++ b/Python/traceback.c
@@ -700,8 +700,13 @@ extract_anchors_from_line(PyObject *filename, PyObject *line,
done:
if (res > 0) {
- *left_anchor += start_offset;
- *right_anchor += start_offset;
+ // Normalize the AST offsets to byte offsets and adjust them with the
+ // start of the actual line (instead of the source code segment).
+ assert(segment != NULL);
+ assert(*left_anchor >= 0);
+ assert(*right_anchor >= 0);
+ *left_anchor = _PyPegen_byte_offset_to_character_offset(segment, *left_anchor) + start_offset;
+ *right_anchor = _PyPegen_byte_offset_to_character_offset(segment, *right_anchor) + start_offset;
}
Py_XDECREF(segment);
if (arena) {