summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2022-01-11 16:30:39 (GMT)
committerGitHub <noreply@github.com>2022-01-11 16:30:39 (GMT)
commitcedec19be81e6bd153678bfb28c8e217af8bda58 (patch)
tree590d988a1ebbac4e8677c336099654d4bb155c2a /Parser
parent43c5c1369cb21f08a1dc1d63923c3586b883e3e8 (diff)
downloadcpython-cedec19be81e6bd153678bfb28c8e217af8bda58.zip
cpython-cedec19be81e6bd153678bfb28c8e217af8bda58.tar.gz
cpython-cedec19be81e6bd153678bfb28c8e217af8bda58.tar.bz2
bpo-46339: Fix crash in the parser when computing error text for multi-line f-strings (GH-30529)
Automerge-Triggered-By: GH:pablogsal
Diffstat (limited to 'Parser')
-rw-r--r--Parser/pegen_errors.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/Parser/pegen_errors.c b/Parser/pegen_errors.c
index f07d9d8..bffae85 100644
--- a/Parser/pegen_errors.c
+++ b/Parser/pegen_errors.c
@@ -250,8 +250,15 @@ get_error_line_from_tokenizer_buffers(Parser *p, Py_ssize_t lineno)
char *cur_line = p->tok->fp_interactive ? p->tok->interactive_src_start : p->tok->str;
assert(cur_line != NULL);
- for (int i = 0; i < lineno - 1; i++) {
- cur_line = strchr(cur_line, '\n') + 1;
+ Py_ssize_t relative_lineno = p->starting_lineno ? lineno - p->starting_lineno + 1 : lineno;
+
+ for (int i = 0; i < relative_lineno - 1; i++) {
+ char *new_line = strchr(cur_line, '\n') + 1;
+ assert(new_line != NULL && new_line < p->tok->inp);
+ if (new_line == NULL || new_line >= p->tok->inp) {
+ break;
+ }
+ cur_line = new_line;
}
char *next_newline;