diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2021-11-14 01:47:27 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-14 01:47:27 (GMT) |
commit | 142fcb40b6e460fa9b4a89fe9846b1ce4176354e (patch) | |
tree | 0b9561fbe6a6db3b46c99fde6a5edf5893cb1503 /Parser | |
parent | 3e0b830e859ca8792401bfd1402d659f56f99941 (diff) | |
download | cpython-142fcb40b6e460fa9b4a89fe9846b1ce4176354e.zip cpython-142fcb40b6e460fa9b4a89fe9846b1ce4176354e.tar.gz cpython-142fcb40b6e460fa9b4a89fe9846b1ce4176354e.tar.bz2 |
bpo-45738: Fix computation of error location for invalid continuation characters in the parser (GH-29550) (GH-29552)
(cherry picked from commit 25835c518aa7446f3680b62c1fb43827e0f190d9)
Diffstat (limited to 'Parser')
-rw-r--r-- | Parser/pegen/pegen.c | 12 | ||||
-rw-r--r-- | Parser/tokenizer.c | 1 |
2 files changed, 3 insertions, 10 deletions
diff --git a/Parser/pegen/pegen.c b/Parser/pegen/pegen.c index 98de05c..efcf9ac 100644 --- a/Parser/pegen/pegen.c +++ b/Parser/pegen/pegen.c @@ -348,14 +348,7 @@ tokenizer_error(Parser *p) msg = "too many levels of indentation"; break; case E_LINECONT: { - char* loc = strrchr(p->tok->buf, '\n'); - const char* last_char = p->tok->cur - 1; - if (loc != NULL && loc != last_char) { - col_offset = p->tok->cur - loc - 1; - p->tok->buf = loc; - } else { - col_offset = last_char - p->tok->buf - 1; - } + col_offset = p->tok->cur - p->tok->buf - 1; msg = "unexpected character after line continuation character"; break; } @@ -363,7 +356,8 @@ tokenizer_error(Parser *p) msg = "unknown parsing error"; } - RAISE_ERROR_KNOWN_LOCATION(p, errtype, p->tok->lineno, col_offset, msg); + RAISE_ERROR_KNOWN_LOCATION(p, errtype, p->tok->lineno, + col_offset >= 0 ? col_offset : 0, msg); return -1; } diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 1a57db9..41bfdb8 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -1752,7 +1752,6 @@ tok_get(struct tok_state *tok, const char **p_start, const char **p_end) c = tok_nextc(tok); if (c != '\n') { tok->done = E_LINECONT; - tok->cur = tok->inp; return ERRORTOKEN; } c = tok_nextc(tok); |