diff options
| author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2022-07-05 17:39:21 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-05 17:39:21 +0100 |
| commit | 36fcde61ba48c4e918830691ecf4092e4e3b9b99 (patch) | |
| tree | 4018f279199d9ccf74ef0100dcb62a6135a915c3 /Parser/pegen_errors.c | |
| parent | c8556bcf6c0b05ac46bd74880626a2853e7c99a1 (diff) | |
| download | cpython-git-36fcde61ba48c4e918830691ecf4092e4e3b9b99.tar.gz | |
gh-94360: Fix a tokenizer crash when reading encoded files with syntax errors from stdin (#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>
Diffstat (limited to 'Parser/pegen_errors.c')
| -rw-r--r-- | Parser/pegen_errors.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/Parser/pegen_errors.c b/Parser/pegen_errors.c index 4896996796..5703088443 100644 --- a/Parser/pegen_errors.c +++ b/Parser/pegen_errors.c @@ -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; |
