mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-46339: Fix crash in the parser when computing error text for multi-line f-strings (GH-30529)
Automerge-Triggered-By: GH:pablogsal
This commit is contained in:
parent
43c5c1369c
commit
cedec19be8
3 changed files with 18 additions and 2 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue