Skip to content

Commit 27c3d73

Browse files
committed
gh-153569: Avoid overflow when sizing implicit line flags
1 parent 2bdef78 commit 27c3d73

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

Parser/tokenizer/source.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ _PyTok_SourceDiscard(_PyTok_SourceText *source)
2929
source->bytes[0] = '\0';
3030
}
3131
if (source->implicit_lines != NULL) {
32-
memset(source->implicit_lines, 0,
33-
Py_MIN(((Py_ssize_t)source->nlines + 7) / 8,
34-
source->implicit_cap));
32+
Py_ssize_t used = source->nlines / 8 + (source->nlines % 8 != 0);
33+
memset(source->implicit_lines, 0, Py_MIN(used, source->implicit_cap));
3534
}
3635
source->nlines = 0;
3736
}
@@ -106,7 +105,7 @@ reserve_checkpoints(_PyTok_SourceText *source, int needed)
106105
static int
107106
reserve_implicit_lines(_PyTok_SourceText *source, int nlines)
108107
{
109-
Py_ssize_t needed = ((Py_ssize_t)nlines + 7) / 8;
108+
Py_ssize_t needed = nlines / 8 + (nlines % 8 != 0);
110109
if (needed <= source->implicit_cap) {
111110
return 0;
112111
}

0 commit comments

Comments
 (0)