Skip to content

Commit 155c191

Browse files
committed
requested size_t change
1 parent d545dc4 commit 155c191

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

Modules/arraymodule.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,9 @@ enum machine_format_code {
152152
#define array_Check(op, state) PyObject_TypeCheck(op, state->ArrayType)
153153

154154
static inline bool
155-
arraydata_size_valid(Py_ssize_t size, int itemsize)
155+
arraydata_size_valid(size_t size, int itemsize)
156156
{
157-
return size >= 0 &&
158-
size <= (PY_SSIZE_T_MAX - (Py_ssize_t)sizeof(arraydata)) / itemsize;
157+
return size <= (size_t)((PY_SSIZE_T_MAX - (Py_ssize_t)sizeof(arraydata)) / itemsize);
159158
}
160159

161160
static arraydata *
@@ -269,11 +268,6 @@ array_resize(arrayobject *self, Py_ssize_t newsize)
269268
*/
270269

271270
size_t _new_size = (newsize >> 4) + (Py_SIZE(self) < 8 ? 3 : 7) + newsize;
272-
// Limit over-allocation to not overflow Py_ssize_t, newsize can't ever be
273-
// larger than this anyway.
274-
if (_new_size > PY_SSIZE_T_MAX) {
275-
_new_size = PY_SSIZE_T_MAX;
276-
}
277271
int itemsize = self->ob_descr->itemsize;
278272

279273
if (!arraydata_size_valid(_new_size, itemsize)) {
@@ -2123,7 +2117,6 @@ array_array_fromunicode_impl(arrayobject *self, PyObject *ustr)
21232117
if (ustr_length > 1) {
21242118
ustr_length--; /* trim trailing NUL character */
21252119
Py_ssize_t old_size = Py_SIZE(self);
2126-
// if overflows PY_SSIZE_T_MAX arraydata_size_valid() will catch it
21272120
Py_ssize_t new_size = old_size + ustr_length;
21282121

21292122
if (!arraydata_size_valid(new_size, sizeof(wchar_t))) {
@@ -2141,7 +2134,6 @@ array_array_fromunicode_impl(arrayobject *self, PyObject *ustr)
21412134
else { // typecode == 'w'
21422135
Py_ssize_t ustr_length = PyUnicode_GetLength(ustr);
21432136
Py_ssize_t old_size = Py_SIZE(self);
2144-
// if overflows PY_SSIZE_T_MAX arraydata_size_valid() will catch it
21452137
Py_ssize_t new_size = old_size + ustr_length;
21462138

21472139
if (!arraydata_size_valid(new_size, sizeof(Py_UCS4))) {

0 commit comments

Comments
 (0)