mirror of
https://github.com/python/cpython.git
synced 2025-08-17 15:21:26 +00:00
Merged revisions 78183-78184 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r78183 | mark.dickinson | 2010-02-14 12:16:43 +0000 (Sun, 14 Feb 2010) | 1 line Silence some 'comparison between signed and unsigned' compiler warnings. ........ r78184 | mark.dickinson | 2010-02-14 12:31:26 +0000 (Sun, 14 Feb 2010) | 1 line Silence more compiler warnings; fix an instance of potential undefined behaviour from signed overflow. ........
This commit is contained in:
parent
71e38f57f3
commit
a920961673
2 changed files with 13 additions and 11 deletions
|
@ -713,7 +713,7 @@ bytes_ass_subscript(PyByteArrayObject *self, PyObject *index, PyObject *values)
|
||||||
i < slicelen; cur += step, i++) {
|
i < slicelen; cur += step, i++) {
|
||||||
Py_ssize_t lim = step - 1;
|
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;
|
lim = PyByteArray_GET_SIZE(self) - cur - 1;
|
||||||
|
|
||||||
memmove(self->ob_bytes + cur - i,
|
memmove(self->ob_bytes + cur - i,
|
||||||
|
@ -721,7 +721,7 @@ bytes_ass_subscript(PyByteArrayObject *self, PyObject *index, PyObject *values)
|
||||||
}
|
}
|
||||||
/* Move the tail of the bytes, in one chunk */
|
/* Move the tail of the bytes, in one chunk */
|
||||||
cur = start + slicelen*step;
|
cur = start + slicelen*step;
|
||||||
if (cur < PyByteArray_GET_SIZE(self)) {
|
if (cur < (size_t)PyByteArray_GET_SIZE(self)) {
|
||||||
memmove(self->ob_bytes + cur - slicelen,
|
memmove(self->ob_bytes + cur - slicelen,
|
||||||
self->ob_bytes + cur,
|
self->ob_bytes + cur,
|
||||||
PyByteArray_GET_SIZE(self) - cur);
|
PyByteArray_GET_SIZE(self) - cur);
|
||||||
|
@ -921,13 +921,14 @@ bytes_repr(PyByteArrayObject *self)
|
||||||
const char *quote_postfix = ")";
|
const char *quote_postfix = ")";
|
||||||
Py_ssize_t length = Py_SIZE(self);
|
Py_ssize_t length = Py_SIZE(self);
|
||||||
/* 14 == strlen(quote_prefix) + 2 + strlen(quote_postfix) */
|
/* 14 == strlen(quote_prefix) + 2 + strlen(quote_postfix) */
|
||||||
size_t newsize = 14 + 4 * length;
|
size_t newsize;
|
||||||
PyObject *v;
|
PyObject *v;
|
||||||
if (newsize > PY_SSIZE_T_MAX || newsize / 4 - 3 != length) {
|
if (length > (PY_SSIZE_T_MAX - 14) / 4) {
|
||||||
PyErr_SetString(PyExc_OverflowError,
|
PyErr_SetString(PyExc_OverflowError,
|
||||||
"bytearray object is too large to make repr");
|
"bytearray object is too large to make repr");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
newsize = 14 + 4 * length;
|
||||||
v = PyUnicode_FromUnicode(NULL, newsize);
|
v = PyUnicode_FromUnicode(NULL, newsize);
|
||||||
if (v == NULL) {
|
if (v == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -126,11 +126,11 @@ PyList_New(Py_ssize_t size)
|
||||||
PyErr_BadInternalCall();
|
PyErr_BadInternalCall();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
nbytes = size * sizeof(PyObject *);
|
|
||||||
/* Check for overflow without an actual overflow,
|
/* Check for overflow without an actual overflow,
|
||||||
* which can cause compiler to optimise out */
|
* which can cause compiler to optimise out */
|
||||||
if (size > PY_SIZE_MAX / sizeof(PyObject *))
|
if ((size_t)size > PY_SIZE_MAX / sizeof(PyObject *))
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
|
nbytes = size * sizeof(PyObject *);
|
||||||
if (numfree) {
|
if (numfree) {
|
||||||
numfree--;
|
numfree--;
|
||||||
op = free_list[numfree];
|
op = free_list[numfree];
|
||||||
|
@ -1426,7 +1426,7 @@ merge_getmem(MergeState *ms, Py_ssize_t need)
|
||||||
* we don't care what's in the block.
|
* we don't care what's in the block.
|
||||||
*/
|
*/
|
||||||
merge_freemem(ms);
|
merge_freemem(ms);
|
||||||
if (need > PY_SSIZE_T_MAX / sizeof(PyObject*)) {
|
if ((size_t)need > PY_SSIZE_T_MAX / sizeof(PyObject*)) {
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -2616,7 +2616,8 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
|
||||||
step = -step;
|
step = -step;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(slicelength <= PY_SIZE_MAX / sizeof(PyObject*));
|
assert((size_t)slicelength <=
|
||||||
|
PY_SIZE_MAX / sizeof(PyObject*));
|
||||||
|
|
||||||
garbage = (PyObject**)
|
garbage = (PyObject**)
|
||||||
PyMem_MALLOC(slicelength*sizeof(PyObject*));
|
PyMem_MALLOC(slicelength*sizeof(PyObject*));
|
||||||
|
@ -2632,13 +2633,13 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
|
||||||
and then tail end of the list that was not
|
and then tail end of the list that was not
|
||||||
covered by the slice */
|
covered by the slice */
|
||||||
for (cur = start, i = 0;
|
for (cur = start, i = 0;
|
||||||
cur < stop;
|
cur < (size_t)stop;
|
||||||
cur += step, i++) {
|
cur += step, i++) {
|
||||||
Py_ssize_t lim = step - 1;
|
Py_ssize_t lim = step - 1;
|
||||||
|
|
||||||
garbage[i] = PyList_GET_ITEM(self, cur);
|
garbage[i] = PyList_GET_ITEM(self, cur);
|
||||||
|
|
||||||
if (cur + step >= Py_SIZE(self)) {
|
if (cur + step >= (size_t)Py_SIZE(self)) {
|
||||||
lim = Py_SIZE(self) - cur - 1;
|
lim = Py_SIZE(self) - cur - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2647,7 +2648,7 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
|
||||||
lim * sizeof(PyObject *));
|
lim * sizeof(PyObject *));
|
||||||
}
|
}
|
||||||
cur = start + slicelength*step;
|
cur = start + slicelength*step;
|
||||||
if (cur < Py_SIZE(self)) {
|
if (cur < (size_t)Py_SIZE(self)) {
|
||||||
memmove(self->ob_item + cur - slicelength,
|
memmove(self->ob_item + cur - slicelength,
|
||||||
self->ob_item + cur,
|
self->ob_item + cur,
|
||||||
(Py_SIZE(self) - cur) *
|
(Py_SIZE(self) - cur) *
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue