bpo-46339: Include clarification on assert in 'get_error_line_from_tokenizer_buffers' (#30545)

This commit is contained in:
Pablo Galindo Salgado 2022-01-18 11:13:00 +00:00 committed by GitHub
parent 243c31667c
commit 8c2fd09f36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 0 deletions

View File

@ -254,6 +254,9 @@ get_error_line_from_tokenizer_buffers(Parser *p, Py_ssize_t lineno)
for (int i = 0; i < relative_lineno - 1; i++) { for (int i = 0; i < relative_lineno - 1; i++) {
char *new_line = strchr(cur_line, '\n') + 1; char *new_line = strchr(cur_line, '\n') + 1;
// 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 < p->tok->inp); assert(new_line != NULL && new_line < p->tok->inp);
if (new_line == NULL || new_line >= p->tok->inp) { if (new_line == NULL || new_line >= p->tok->inp) {
break; break;