diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2023-05-26 14:46:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-26 14:46:22 (GMT) |
commit | 3fdb55c48291a459fb1e33edb5140ec0383222df (patch) | |
tree | 4c55319f16464b4fde991419d6f51583c4e8628f /Python | |
parent | 2cb445635e99d4401949cabebd373288cfdd0138 (diff) | |
download | cpython-3fdb55c48291a459fb1e33edb5140ec0383222df.zip cpython-3fdb55c48291a459fb1e33edb5140ec0383222df.tar.gz cpython-3fdb55c48291a459fb1e33edb5140ec0383222df.tar.bz2 |
gh-104972: Ensure that line attributes in tokens in the tokenize module are correct (#104975)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/Python-tokenize.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/Python/Python-tokenize.c b/Python/Python-tokenize.c index 0023e30..88087c1 100644 --- a/Python/Python-tokenize.c +++ b/Python/Python-tokenize.c @@ -194,15 +194,14 @@ tokenizeriter_next(tokenizeriterobject *it) goto exit; } - Py_ssize_t size = it->tok->inp - it->tok->buf; - assert(it->tok->buf[size-1] == '\n'); - size -= 1; // Remove the newline character from the end of the line - PyObject *line = PyUnicode_DecodeUTF8(it->tok->buf, size, "replace"); + const char *line_start = ISSTRINGLIT(type) ? it->tok->multi_line_start : it->tok->line_start; + Py_ssize_t size = it->tok->inp - line_start; + PyObject *line = PyUnicode_DecodeUTF8(line_start, size, "replace"); if (line == NULL) { Py_DECREF(str); goto exit; } - const char *line_start = ISSTRINGLIT(type) ? it->tok->multi_line_start : it->tok->line_start; + Py_ssize_t lineno = ISSTRINGLIT(type) ? it->tok->first_lineno : it->tok->lineno; Py_ssize_t end_lineno = it->tok->lineno; Py_ssize_t col_offset = -1; |