mirror of
https://github.com/python/cpython.git
synced 2025-09-11 11:17:16 +00:00
gh-94360: Fix a tokenizer crash when reading encoded files with syntax errors from stdin (GH-94386)
* gh-94360: Fix a tokenizer crash when reading encoded files with syntax errors from stdin
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
* nitty nit
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 36fcde61ba
)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
This commit is contained in:
parent
9bd97a2a7e
commit
d49c99f10d
3 changed files with 15 additions and 5 deletions
|
@ -259,15 +259,15 @@ get_error_line_from_tokenizer_buffers(Parser *p, Py_ssize_t lineno)
|
|||
const char* buf_end = p->tok->fp_interactive ? p->tok->interactive_src_end : p->tok->inp;
|
||||
|
||||
for (int i = 0; i < relative_lineno - 1; i++) {
|
||||
char *new_line = strchr(cur_line, '\n') + 1;
|
||||
char *new_line = strchr(cur_line, '\n');
|
||||
// The assert is here for debug builds but the conditional that
|
||||
// follows is there so in release builds we do not crash at the cost
|
||||
// to report a potentially wrong line.
|
||||
assert(new_line != NULL && new_line <= buf_end);
|
||||
if (new_line == NULL || new_line > buf_end) {
|
||||
assert(new_line != NULL && new_line + 1 < buf_end);
|
||||
if (new_line == NULL || new_line + 1 > buf_end) {
|
||||
break;
|
||||
}
|
||||
cur_line = new_line;
|
||||
cur_line = new_line + 1;
|
||||
}
|
||||
|
||||
char *next_newline;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue