From 57be5459593bbd09583317ebdafc4d58ae51dbf4 Mon Sep 17 00:00:00 2001 From: Batuhan Taskaya Date: Sun, 13 Nov 2022 02:37:25 +0300 Subject: gh-99103: Normalize specialized traceback anchors against the current line (GH-99145) Automerge-Triggered-By: GH:isidentical --- Python/traceback.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'Python/traceback.c') diff --git a/Python/traceback.c b/Python/traceback.c index aacdb33d39..356e643648 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) { -- cgit v1.2.1