In function isum in summary.c, k should be R_xlen_t

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

In function isum in summary.c, k should be R_xlen_t

R devel mailing list

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.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: In function isum in summary.c, k should be R_xlen_t

Jan Gorecki
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 <[hidden email]> 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.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel