diff options
author | Alexandre Vassalotti <alexandre@peadrop.com> | 2008-05-07 01:44:31 (GMT) |
---|---|---|
committer | Alexandre Vassalotti <alexandre@peadrop.com> | 2008-05-07 01:44:31 (GMT) |
commit | 1bfe9dc871bb3cd6392418410805f0248b1c7d87 (patch) | |
tree | 8ea1da7f4758239c2660085d02079cd647a7a1a9 /Modules/_bytesio.c | |
parent | 2e0419dcd69cab245d30b92a7f442fd4617ca8f8 (diff) | |
download | cpython-1bfe9dc871bb3cd6392418410805f0248b1c7d87.zip cpython-1bfe9dc871bb3cd6392418410805f0248b1c7d87.tar.gz cpython-1bfe9dc871bb3cd6392418410805f0248b1c7d87.tar.bz2 |
Changed _bytesio.c to avoid comparing a signed with an unsigned value.
Added tests for overflow checks.
Diffstat (limited to 'Modules/_bytesio.c')
-rw-r--r-- | Modules/_bytesio.c | 12 |
1 files changed, 2 insertions, 10 deletions
diff --git a/Modules/_bytesio.c b/Modules/_bytesio.c index 00cb06b..9920aaa 100644 --- a/Modules/_bytesio.c +++ b/Modules/_bytesio.c @@ -110,16 +110,8 @@ write_bytes(BytesIOObject *self, const char *bytes, Py_ssize_t len) 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; } |