Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 66f575b

Browse files
committed
Merged revisions 78183-78184 via svnmerge from
svn+ssh://[email protected]/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. ........
1 parent 4e51128 commit 66f575b

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

Objects/bytearrayobject.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -656,15 +656,15 @@ bytearray_ass_subscript(PyByteArrayObject *self, PyObject *index, PyObject *valu
656656
i < slicelen; cur += step, i++) {
657657
Py_ssize_t lim = step - 1;
658658

659-
if (cur + step >= PyByteArray_GET_SIZE(self))
659+
if (cur + step >= (size_t)PyByteArray_GET_SIZE(self))
660660
lim = PyByteArray_GET_SIZE(self) - cur - 1;
661661

662662
memmove(self->ob_bytes + cur - i,
663663
self->ob_bytes + cur + 1, lim);
664664
}
665665
/* Move the tail of the bytes, in one chunk */
666666
cur = start + slicelen*step;
667-
if (cur < PyByteArray_GET_SIZE(self)) {
667+
if (cur < (size_t)PyByteArray_GET_SIZE(self)) {
668668
memmove(self->ob_bytes + cur - slicelen,
669669
self->ob_bytes + cur,
670670
PyByteArray_GET_SIZE(self) - cur);
@@ -844,13 +844,14 @@ bytearray_repr(PyByteArrayObject *self)
844844
const char *quote_postfix = ")";
845845
Py_ssize_t length = Py_SIZE(self);
846846
/* 14 == strlen(quote_prefix) + 2 + strlen(quote_postfix) */
847-
size_t newsize = 14 + 4 * length;
847+
size_t newsize;
848848
PyObject *v;
849-
if (newsize > PY_SSIZE_T_MAX || newsize / 4 - 3 != length) {
849+
if (length > (PY_SSIZE_T_MAX - 14) / 4) {
850850
PyErr_SetString(PyExc_OverflowError,
851851
"bytearray object is too large to make repr");
852852
return NULL;
853853
}
854+
newsize = 14 + 4 * length;
854855
v = PyUnicode_FromUnicode(NULL, newsize);
855856
if (v == NULL) {
856857
return NULL;

Objects/listobject.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ PyList_New(Py_ssize_t size)
126126
PyErr_BadInternalCall();
127127
return NULL;
128128
}
129-
nbytes = size * sizeof(PyObject *);
130129
/* Check for overflow without an actual overflow,
131130
* which can cause compiler to optimise out */
132-
if (size > PY_SIZE_MAX / sizeof(PyObject *))
131+
if ((size_t)size > PY_SIZE_MAX / sizeof(PyObject *))
133132
return PyErr_NoMemory();
133+
nbytes = size * sizeof(PyObject *);
134134
if (numfree) {
135135
numfree--;
136136
op = free_list[numfree];
@@ -1343,7 +1343,7 @@ merge_getmem(MergeState *ms, Py_ssize_t need)
13431343
* we don't care what's in the block.
13441344
*/
13451345
merge_freemem(ms);
1346-
if (need > PY_SSIZE_T_MAX / sizeof(PyObject*)) {
1346+
if ((size_t)need > PY_SSIZE_T_MAX / sizeof(PyObject*)) {
13471347
PyErr_NoMemory();
13481348
return -1;
13491349
}
@@ -2456,7 +2456,8 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
24562456
step = -step;
24572457
}
24582458

2459-
assert(slicelength <= PY_SIZE_MAX / sizeof(PyObject*));
2459+
assert((size_t)slicelength <=
2460+
PY_SIZE_MAX / sizeof(PyObject*));
24602461

24612462
garbage = (PyObject**)
24622463
PyMem_MALLOC(slicelength*sizeof(PyObject*));
@@ -2472,13 +2473,13 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
24722473
and then tail end of the list that was not
24732474
covered by the slice */
24742475
for (cur = start, i = 0;
2475-
cur < stop;
2476+
cur < (size_t)stop;
24762477
cur += step, i++) {
24772478
Py_ssize_t lim = step - 1;
24782479

24792480
garbage[i] = PyList_GET_ITEM(self, cur);
24802481

2481-
if (cur + step >= Py_SIZE(self)) {
2482+
if (cur + step >= (size_t)Py_SIZE(self)) {
24822483
lim = Py_SIZE(self) - cur - 1;
24832484
}
24842485

@@ -2487,7 +2488,7 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
24872488
lim * sizeof(PyObject *));
24882489
}
24892490
cur = start + slicelength*step;
2490-
if (cur < Py_SIZE(self)) {
2491+
if (cur < (size_t)Py_SIZE(self)) {
24912492
memmove(self->ob_item + cur - slicelength,
24922493
self->ob_item + cur,
24932494
(Py_SIZE(self) - cur) *

0 commit comments

Comments
 (0)