summaryrefslogtreecommitdiffstats
path: root/Parser/pegen_errors.c
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2022-01-20 15:34:13 (GMT)
committerGitHub <noreply@github.com>2022-01-20 15:34:13 (GMT)
commit650720a0cfa1673938e6d1bad53b6c37c9edb47d (patch)
tree4fade9a6e2a49af3fc936a5ce7a47eebd9da997f /Parser/pegen_errors.c
parentb04dfbbe4bd7071d46c8688c2263726ea31d33cd (diff)
downloadcpython-650720a0cfa1673938e6d1bad53b6c37c9edb47d.zip
cpython-650720a0cfa1673938e6d1bad53b6c37c9edb47d.tar.gz
cpython-650720a0cfa1673938e6d1bad53b6c37c9edb47d.tar.bz2
Fix the caret position in some syntax errors in interactive mode (GH-30718)
Diffstat (limited to 'Parser/pegen_errors.c')
-rw-r--r--Parser/pegen_errors.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/Parser/pegen_errors.c b/Parser/pegen_errors.c
index f348ac3..0be9df0 100644
--- a/Parser/pegen_errors.c
+++ b/Parser/pegen_errors.c
@@ -251,14 +251,15 @@ get_error_line_from_tokenizer_buffers(Parser *p, Py_ssize_t lineno)
assert(cur_line != NULL);
Py_ssize_t relative_lineno = p->starting_lineno ? lineno - p->starting_lineno + 1 : lineno;
+ const char* buf_end = p->tok->fp_interactive ? p->tok->interactive_src_end : p->tok->inp;
for (int i = 0; i < relative_lineno - 1; i++) {
char *new_line = strchr(cur_line, '\n') + 1;
// The assert is here for debug builds but the conditional that
// follows is there so in release builds we do not crash at the cost
// to report a potentially wrong line.
- assert(new_line != NULL && new_line < p->tok->inp);
- if (new_line == NULL || new_line >= p->tok->inp) {
+ assert(new_line != NULL && new_line <= buf_end);
+ if (new_line == NULL || new_line > buf_end) {
break;
}
cur_line = new_line;