[issue9783] _elementtree.c warnings under 64-bit Windows

Jon Anglin report at bugs.python.org
Sat Sep 25 15:07:08 CEST 2010


Jon Anglin <janglin at fortresgrand.com> added the comment:

Martin is correct about this patch.

> In cases where we really can't propagate Py_ssize_t to (e.g.
> XML_Parse), we need to check for an int overflow, and raise
> an exception if it does overflow.

Is this an appropriate approach?

int
PySize_AsInt(Py_ssize_t value)
{
    if (value > (Py_ssize_t)INT_MAX || value < (Py_ssize_t)INT_MIN) {
        PyErr_SetString(PyExc_OverflowError, 
                        "Size value can not be represented as an integer");
    }
    return (int)value;
}

I would only define this when sizeof(Py_ssize_t) > sizeof(int) of course. In other cases it would be a macro that just evaluates to value.
I would most likely need an unsigned version as well (although not for this particular issue).

This code could be used in many C modules. Where in the Python code base should such functions be placed?

----------

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


More information about the Python-bugs-list mailing list