mirror of
https://github.com/python/cpython.git
synced 2025-09-28 11:15:17 +00:00
gh-104016: Fixed off by 1 error in f string tokenizer (#104047)
Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com> Co-authored-by: Ken Jin <kenjin@python.org> Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
This commit is contained in:
parent
2d526cd32f
commit
5078eedc5b
3 changed files with 25 additions and 5 deletions
|
@ -43,12 +43,12 @@
|
|||
#ifdef Py_DEBUG
|
||||
static inline tokenizer_mode* TOK_GET_MODE(struct tok_state* tok) {
|
||||
assert(tok->tok_mode_stack_index >= 0);
|
||||
assert(tok->tok_mode_stack_index < MAXLEVEL);
|
||||
assert(tok->tok_mode_stack_index < MAXFSTRINGLEVEL);
|
||||
return &(tok->tok_mode_stack[tok->tok_mode_stack_index]);
|
||||
}
|
||||
static inline tokenizer_mode* TOK_NEXT_MODE(struct tok_state* tok) {
|
||||
assert(tok->tok_mode_stack_index >= 0);
|
||||
assert(tok->tok_mode_stack_index < MAXLEVEL);
|
||||
assert(tok->tok_mode_stack_index + 1 < MAXFSTRINGLEVEL);
|
||||
return &(tok->tok_mode_stack[++tok->tok_mode_stack_index]);
|
||||
}
|
||||
#else
|
||||
|
@ -2235,6 +2235,9 @@ tok_get_normal_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct t
|
|||
|
||||
p_start = tok->start;
|
||||
p_end = tok->cur;
|
||||
if (tok->tok_mode_stack_index + 1 >= MAXFSTRINGLEVEL) {
|
||||
return MAKE_TOKEN(syntaxerror(tok, "too many nested f-strings"));
|
||||
}
|
||||
tokenizer_mode *the_current_tok = TOK_NEXT_MODE(tok);
|
||||
the_current_tok->kind = TOK_FSTRING_MODE;
|
||||
the_current_tok->f_string_quote = quote;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue