Message152400
| Author |
mark.dickinson |
| Recipients |
Voo, akira, amaury.forgeotdarc, jcea, mark.dickinson, pitrou, rhettinger, tim.peters |
| Date |
2012年01月31日.17:50:56 |
| SpamBayes Score |
6.5075747e-06 |
| Marked as misclassified |
No |
| Message-id |
<1328032257.57.0.46607816978.issue13496@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
> 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.) |
|