[issue13496] bisect module: Overflow at index computation
Mark Dickinson
report at bugs.python.org
Tue Jan 31 18:50:57 CET 2012
Mark Dickinson <dickinsm at gmail.com> added the comment:
> I think the patch is *NOT* correct.
Can you elaborate? It works fine for that example on a 64-bit build; not sure why 32-bit would be any different.
The idea is just that the single cast forces the addition to be done as an addition of integers of type size_t. Since the integers being added are (a) nonnegative and (b) both fit into a Py_ssize_t, the sum fits into a size_t without overflow, and the result of dividing the sum by 2 fits into a size_t.
(This is all assuming that 2*Py_SSIZE_T_MAX fits into a size_t, but that's a fairly safe assumption in practice.)
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13496>
_______________________________________
More information about the Python-bugs-list
mailing list