[Python-Dev] Before 2.5 - More signed integer overflows

Neal Norwitz nnorwitz at gmail.com
Mon Sep 18 08:29:56 CEST 2006


I also tested the fix (see patch below) for the abs() issue and it
seemed to work for 4.1.1 on 64-bit.  I'll apply the patch to head and
2.5 and a test after 2.5 is out.

I have no idea how to search for these problems.  I know that xrange
can't display -sys.maxint-1 properly, but I think it works properly.

n
--

Index: Objects/intobject.c
===================================================================
--- Objects/intobject.c (revision 51886)
+++ Objects/intobject.c (working copy)
@@ -763,7 +763,7 @@
        register long a, x;
        a = v->ob_ival;
        x = -a;
-       if (a < 0 && x < 0) {
+       if (a < 0 && (unsigned long)x == 0-(unsigned long)x) {
                PyObject *o = PyLong_FromLong(a);
                if (o != NULL) {
                        PyObject *result = PyNumber_Negative(o);


On 9/17/06, "Martin v. Löwis" <martin at v.loewis.de> wrote:
> > BTW, did anyone try compiling Python with -fwrapv on a box where it
> > matters?  I doubt that Python's speed is affected one way or the
> > other, and if adding wrapv makes the problems go away, that would be
> > an easy last-second workaround for all possible such problems (which
> > of course could get fixed "for real" for 2.5.1, provided someone cares
> > enough to dig into it).
>
> It's not so easy to add this option: configure needs to be taught to
> check whether the option is supported first; to test it, you ideally
> need an installation where it is supported, and one where it isn't.
>
> I've added a note to README indicating that GCC 4.2 shouldn't be
> used to compile Python. I don't consider this a terrible limitation,
> especially since GCC 4.2 isn't released, yet.
>
> OTOH, I get the same problem that Armin gets (abs(-sys.maxint-1)
> is negative) also on a 32-bit system, with Debian's gcc 4.1.2
> (which also isn't released, yet), so it appears that the problem
> is already with gcc 4.1.
>
> On my system, adding -fwrapv indeed solves the problem
> (tested for abs()). So I added this to the README also.
>
> Regards,
> Martin
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/nnorwitz%40gmail.com
>


More information about the Python-Dev mailing list