diff options
-rw-r--r-- | Modules/cStringIO.c | 9 | ||||
-rw-r--r-- | Objects/stringobject.c | 19 |
2 files changed, 11 insertions, 17 deletions
diff --git a/Modules/cStringIO.c b/Modules/cStringIO.c index 1420bce..7e75879 100644 --- a/Modules/cStringIO.c +++ b/Modules/cStringIO.c @@ -336,8 +336,8 @@ O_seek(Oobject *self, PyObject *args) { if (position > self->buf_size) { self->buf_size*=2; if (self->buf_size <= position) self->buf_size=position+1; - UNLESS (self->buf=(char*) - realloc(self->buf,self->buf_size*sizeof(char))) { + UNLESS (self->buf = (char*) + realloc(self->buf,self->buf_size)) { self->buf_size=self->pos=0; return PyErr_NoMemory(); } @@ -371,8 +371,7 @@ O_cwrite(PyObject *self, char *c, int l) { if (oself->buf_size <= newl) oself->buf_size = newl+1; UNLESS (oself->buf = - (char*)realloc(oself->buf, - (oself->buf_size) * sizeof(char))) { + (char*)realloc(oself->buf, oself->buf_size)) { PyErr_SetString(PyExc_MemoryError,"out of memory"); oself->buf_size = oself->pos = 0; return -1; @@ -529,7 +528,7 @@ newOobject(int size) { self->string_size = 0; self->softspace = 0; - UNLESS (self->buf=malloc(size*sizeof(char))) { + UNLESS (self->buf = (char *)malloc(size)) { PyErr_SetString(PyExc_MemoryError,"out of memory"); self->buf_size = 0; return NULL; diff --git a/Objects/stringobject.c b/Objects/stringobject.c index b14dc51..7fade56 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -70,8 +70,7 @@ PyString_FromStringAndSize(const char *str, int size) } /* Inline PyObject_NewVar */ - op = (PyStringObject *) - PyObject_MALLOC(sizeof(PyStringObject) + size * sizeof(char)); + op = (PyStringObject *)PyObject_MALLOC(sizeof(PyStringObject) + size); if (op == NULL) return PyErr_NoMemory(); PyObject_INIT_VAR(op, &PyString_Type, size); @@ -126,8 +125,7 @@ PyString_FromString(const char *str) } /* Inline PyObject_NewVar */ - op = (PyStringObject *) - PyObject_MALLOC(sizeof(PyStringObject) + size * sizeof(char)); + op = (PyStringObject *)PyObject_MALLOC(sizeof(PyStringObject) + size); if (op == NULL) return PyErr_NoMemory(); PyObject_INIT_VAR(op, &PyString_Type, size); @@ -799,7 +797,7 @@ PyObject * PyString_Repr(PyObject *obj, int smartquotes) { register PyStringObject* op = (PyStringObject*) obj; - size_t newsize = 2 + 4 * op->ob_size * sizeof(char); + size_t newsize = 2 + 4 * op->ob_size; PyObject *v; if (newsize > INT_MAX) { PyErr_SetString(PyExc_OverflowError, @@ -911,8 +909,7 @@ string_concat(register PyStringObject *a, register PyObject *bb) } size = a->ob_size + b->ob_size; /* Inline PyObject_NewVar */ - op = (PyStringObject *) - PyObject_MALLOC(sizeof(PyStringObject) + size * sizeof(char)); + op = (PyStringObject *)PyObject_MALLOC(sizeof(PyStringObject) + size); if (op == NULL) return PyErr_NoMemory(); PyObject_INIT_VAR(op, &PyString_Type, size); @@ -948,9 +945,8 @@ string_repeat(register PyStringObject *a, register int n) Py_INCREF(a); return (PyObject *)a; } - nbytes = size * sizeof(char); - if (nbytes / sizeof(char) != (size_t)size || - nbytes + sizeof(PyStringObject) <= nbytes) { + nbytes = (size_t)size; + if (nbytes + sizeof(PyStringObject) <= nbytes) { PyErr_SetString(PyExc_OverflowError, "repeated string is too long"); return NULL; @@ -3495,8 +3491,7 @@ _PyString_Resize(PyObject **pv, int newsize) _Py_DEC_REFTOTAL; _Py_ForgetReference(v); *pv = (PyObject *) - PyObject_REALLOC((char *)v, - sizeof(PyStringObject) + newsize * sizeof(char)); + PyObject_REALLOC((char *)v, sizeof(PyStringObject) + newsize); if (*pv == NULL) { PyObject_Del(v); PyErr_NoMemory(); |