Mercurial > cpython-lru_cache-weakref
diff Modules/_bytesio.c @ 46714:5fbd97f1bc35
Changed _bytesio.c to avoid comparing a signed with an unsigned value.
Added tests for overflow checks.
| author | Alexandre Vassalotti <alexandre@peadrop.com> |
|---|---|
| date | Wed, 07 May 2008 01:44:31 +0000 |
| parents | cda816c3a1e4 |
| children | 38b94c097a55 |
line wrap: on
line diff
--- a/Modules/_bytesio.c Wed May 07 00:09:04 2008 +0000 +++ b/Modules/_bytesio.c Wed May 07 01:44:31 2008 +0000 @@ -110,16 +110,8 @@ assert(self->pos >= 0); assert(len >= 0); - /* This overflow check is not strictly necessary. However, it avoids us to - deal with funky things like comparing an unsigned and a signed - integer. */ - if (self->pos > PY_SSIZE_T_MAX - len) { - PyErr_SetString(PyExc_OverflowError, - "new position too large"); - return -1; - } - if (self->pos + len > self->buf_size) { - if (resize_buffer(self, self->pos + len) < 0) + if ((size_t)self->pos + len > self->buf_size) { + if (resize_buffer(self, (size_t)self->pos + len) < 0) return -1; }
