[issue7406] int arithmetic relies on C signed overflow behaviour

2021-10-20 Thread Christian Heimes
Christian Heimes added the comment: Python 2 is no longer supported. Python 3's _PyLong_Add() function doesn't rely on overflow. -- nosy: +christian.heimes resolution: -> out of date stage: needs patch -> resolved status: open -> closed ___ Python

[issue7406] int arithmetic relies on C signed overflow behaviour

2015-06-24 Thread Kevin Shweh
Kevin Shweh added the comment: It looks like the fast paths for INPLACE_ADD and INPLACE_SUBTRACT in Python 2 don't have the cast-to-unsigned fix, so they're still relying on undefined behavior. For example, in INPLACE_ADD: /* INLINE: int + int */ register long

[issue7406] int arithmetic relies on C signed overflow behaviour

2014-10-14 Thread Stefan Krah
Changes by Stefan Krah : -- nosy: -skrah ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.or

[issue7406] int arithmetic relies on C signed overflow behaviour

2013-03-13 Thread Ezio Melotti
Changes by Ezio Melotti : -- nosy: +serhiy.storchaka, skrah ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http

[issue7406] int arithmetic relies on C signed overflow behaviour

2009-12-05 Thread Gregory P. Smith
Changes by Gregory P. Smith : -- nosy: +gregory.p.smith ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://m

[issue7406] int arithmetic relies on C signed overflow behaviour

2009-12-05 Thread Terry J. Reedy
Terry J. Reedy added the comment: Thanks Tim. I see that is back in 3.2 rather than in the shift and mask sections. At least I know what to refer to now. -- ___ Python tracker __

[issue7406] int arithmetic relies on C signed overflow behaviour

2009-12-04 Thread Tim Peters
Tim Peters added the comment: Terry, the language reference also says: """ For the purpose of shift and mask operations, a binary representation is assumed, and negative numbers are represented in a variant of 2's complement which gives the illusion of an infinite string of sign bits extending

[issue7406] int arithmetic relies on C signed overflow behaviour

2009-12-04 Thread Terry J. Reedy
Terry J. Reedy added the comment: I consider the binary bitwise operations, for negative ints, to be either undefined or wrongly implemented. Consider the following (3.1) >>> 3^2 1 >>> -3^2 -1 >>> 3^-2 -3 >>> -3^-2 3 >>> 2^3 1 >>> -2^3 -3 Something change sign just flips the sign of the result,

[issue7406] int arithmetic relies on C signed overflow behaviour

2009-12-04 Thread Mark Dickinson
Mark Dickinson added the comment: Zooko: Yes; that's the sort of solution that's needed if we're not allowed to assume two's complement with the extraordinary value (- sys.maxint - 1) not a trap representation. If we are allowed to assume this, then more efficient solutions are available. Al

[issue7406] int arithmetic relies on C signed overflow behaviour

2009-12-03 Thread Zooko O'Whielacronx
Zooko O'Whielacronx added the comment: Here is a set of macros that I use to test for overflow: http://allmydata.org/trac/libzutil/browser/libzutil/zutilimp.h -- ___ Python tracker

[issue7406] int arithmetic relies on C signed overflow behaviour

2009-12-03 Thread Zooko O'Whielacronx
Zooko O'Whielacronx added the comment: Here is a way to test for overflow which is correct for any C implementation: static PyObject * int_add(PyIntObject *v, PyIntObject *w) { register long a, b; CONVERT_TO_LONG(v, a); CONVERT_TO_LONG(w, b); if (((a>0)&&(b>0)&&(

[issue7406] int arithmetic relies on C signed overflow behaviour

2009-12-02 Thread Mark Dickinson
Mark Dickinson added the comment: Fixed int_sub, int_add, int_mul, and the fast paths for BINARY_ADD and BINARY_SUB in ceval.c, in r76629 (trunk) and r76630 (release26-maint). -- ___ Python tracker ___

[issue7406] int arithmetic relies on C signed overflow behaviour

2009-11-30 Thread Eric Smith
Changes by Eric Smith : -- nosy: +eric.smith ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.

[issue7406] int arithmetic relies on C signed overflow behaviour

2009-11-29 Thread Mark Dickinson
New submission from Mark Dickinson : Much of the code in Objects/intobject.c assumes that an arithmetic operation on signed longs will wrap modulo 2**(bits_in_long) on overflow. However, signed overflow causes undefined behaviour according to the C standards (e.g., C99 6.5, para. 5), and gcc