[issue27660] Replace size_t with Py_ssize_t as the type of local variable in list_resize

Serhiy Storchaka report at bugs.python.org
Tue Aug 2 02:10:56 EDT 2016


Serhiy Storchaka added the comment:

Unsigned type can be used for more efficient checking on integer overflow.

    new_allocated = (newsize >> 3) + (newsize < 9 ? 3 : 6);
    new_allocated += (size_t)newsize;
    if (new_allocated < (size_t)newsize) {
        PyErr_NoMemory();
        return -1;
    }

Checking "new_allocated < (size_t)newsize" can be more efficient than "new_allocated > PY_SSIZE_T_MAX - newsize".

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27660>
_______________________________________


More information about the Python-bugs-list mailing list