summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-05-26 15:25:46 (GMT)
committerGitHub <noreply@github.com>2023-05-26 15:25:46 (GMT)
commit8ca29573a89f78f87380210d02f48410763f507d (patch)
tree7ed4c5022d0a6fffe34dd51912f73e7708bd28f7 /Python
parent01af2b0e516608c831f4c6837087479f45368d21 (diff)
downloadcpython-8ca29573a89f78f87380210d02f48410763f507d.zip
cpython-8ca29573a89f78f87380210d02f48410763f507d.tar.gz
cpython-8ca29573a89f78f87380210d02f48410763f507d.tar.bz2
[3.12] gh-104972: Ensure that line attributes in tokens in the tokenize module are correct (GH-104975) (#104982)
gh-104972: Ensure that line attributes in tokens in the tokenize module are correct (GH-104975) (cherry picked from commit 3fdb55c48291a459fb1e33edb5140ec0383222df) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Diffstat (limited to 'Python')
-rw-r--r--Python/Python-tokenize.c9
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;