summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-02-14 12:31:26 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2010-02-14 12:31:26 (GMT)
commit2d7911eda4866250c58498f0143b9465635fa775 (patch)
treea676bbf6518a15abc92b6c3504ae20c09128e8bb /Objects
parentac5685eb67dd890746892e3a1a44ca32dfa76142 (diff)
downloadcpython-2d7911eda4866250c58498f0143b9465635fa775.zip
cpython-2d7911eda4866250c58498f0143b9465635fa775.tar.gz
cpython-2d7911eda4866250c58498f0143b9465635fa775.tar.bz2
Silence more compiler warnings; fix an instance of potential undefined behaviour from signed overflow.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/bytearrayobject.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index 87c6599..699dec9 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -705,7 +705,7 @@ bytearray_ass_subscript(PyByteArrayObject *self, PyObject *index, PyObject *valu
i < slicelen; cur += step, i++) {
Py_ssize_t lim = step - 1;
- if (cur + step >= PyByteArray_GET_SIZE(self))
+ if (cur + step >= (size_t)PyByteArray_GET_SIZE(self))
lim = PyByteArray_GET_SIZE(self) - cur - 1;
memmove(self->ob_bytes + cur - i,
@@ -713,7 +713,7 @@ bytearray_ass_subscript(PyByteArrayObject *self, PyObject *index, PyObject *valu
}
/* Move the tail of the bytes, in one chunk */
cur = start + slicelen*step;
- if (cur < PyByteArray_GET_SIZE(self)) {
+ if (cur < (size_t)PyByteArray_GET_SIZE(self)) {
memmove(self->ob_bytes + cur - slicelen,
self->ob_bytes + cur,
PyByteArray_GET_SIZE(self) - cur);
@@ -915,13 +915,14 @@ bytearray_repr(PyByteArrayObject *self)
const char *quote_postfix = ")";
Py_ssize_t length = Py_SIZE(self);
/* 14 == strlen(quote_prefix) + 2 + strlen(quote_postfix) */
- size_t newsize = 14 + 4 * length;
+ size_t newsize;
PyObject *v;
- if (newsize > PY_SSIZE_T_MAX || newsize / 4 - 3 != length) {
+ if (length > (PY_SSIZE_T_MAX - 14) / 4) {
PyErr_SetString(PyExc_OverflowError,
"bytearray object is too large to make repr");
return NULL;
}
+ newsize = 14 + 4 * length;
v = PyString_FromStringAndSize(NULL, newsize);
if (v == NULL) {
return NULL;