Skip to content

Commit 650720a

Browse files
authored
Fix the caret position in some syntax errors in interactive mode (GH-30718)
1 parent b04dfbb commit 650720a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Parser/pegen_errors.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,15 @@ get_error_line_from_tokenizer_buffers(Parser *p, Py_ssize_t lineno)
251251
assert(cur_line != NULL);
252252

253253
Py_ssize_t relative_lineno = p->starting_lineno ? lineno - p->starting_lineno + 1 : lineno;
254+
const char* buf_end = p->tok->fp_interactive ? p->tok->interactive_src_end : p->tok->inp;
254255

255256
for (int i = 0; i < relative_lineno - 1; i++) {
256257
char *new_line = strchr(cur_line, '\n') + 1;
257258
// The assert is here for debug builds but the conditional that
258259
// follows is there so in release builds we do not crash at the cost
259260
// to report a potentially wrong line.
260-
assert(new_line != NULL && new_line < p->tok->inp);
261-
if (new_line == NULL || new_line >= p->tok->inp) {
261+
assert(new_line != NULL && new_line <= buf_end);
262+
if (new_line == NULL || new_line > buf_end) {
262263
break;
263264
}
264265
cur_line = new_line;

0 commit comments

Comments
 (0)