Suharto Anggono Suharto Anggono
2020-Dec-22 10:30 UTC
[Rd] In function isum in summary.c, k should be R_xlen_t
In summary.c, in function 'isum', the loop is 'ITERATE_BY_REGION' that contains 'for' loop for (int k = 0; k < nbatch; k++) It is since SVN revision 73445, in released R since version 3.5.0. Previously, the loop is for (R_xlen_t i = 0; i < n; i++) Inside 'ITERATE_BY_REGION', the type of the index, 'k', should still be 'R_xlen_t' as previously. If 'sx' is a regular vector (not ALTREP), data pointer is taken and 'nbatch' is the length of the vector, like without 'ITERATE_BY_REGION'. With 64-bit R, it is possible that the vector is a long vector. In that case, correct iteration should reach index outside the range of 'int'. However, I haven't found an example in 64-bit R of wrong behavior of sum(x) for 'x' with storage mode "integer" and length 2^31 or more.
Jan Gorecki
2020-Dec-31 10:08 UTC
[Rd] In function isum in summary.c, k should be R_xlen_t
Don't know this piece well but I am guessing that you haven't found an example because the iterator is going up to the length of a vector anymore but only to the number of batches, which is unlikely to be more than 2^31. On Tue, Dec 22, 2020 at 12:30 PM Suharto Anggono Suharto Anggono via R-devel <r-devel at r-project.org> wrote:> > > In summary.c, in function 'isum', the loop is 'ITERATE_BY_REGION' that contains 'for' loop > for (int k = 0; k < nbatch; k++) > It is since SVN revision 73445, in released R since version 3.5.0. > Previously, the loop is > for (R_xlen_t i = 0; i < n; i++) > > Inside 'ITERATE_BY_REGION', the type of the index, 'k', should still be 'R_xlen_t' as previously. If 'sx' is a regular vector (not ALTREP), data pointer is taken and 'nbatch' is the length of the vector, like without 'ITERATE_BY_REGION'. With 64-bit R, it is possible that the vector is a long vector. In that case, correct iteration should reach index outside the range of 'int'. > > However, I haven't found an example in 64-bit R of wrong behavior of > sum(x) > for 'x' with storage mode "integer" and length 2^31 or more. > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel