I'm pretty sure this is from this R-devel commit:

https://github.com/r-devel/r-svn/commit/92c1d5de23c93576f55062e26d446feface07250

This turns on stricter boundary checking, specifically see https://github.com/lme4/lme4/issues/794#issuecomment-2154948145

Arguably, accessing an element of a zero-length vector is at least undefined behaviour, so you shouldn't be doing it ...



On 2024-07-08 6:46 p.m., Claborne, Daniel via R-package-devel wrote:
Seemingly starting with the most recent builds of R-devel, I�ve been getting 
segfaults related to a piece of cpp code that indexes a zero-size 
NumericVector.  Essentially the same as this dummy example:

```
library(Rcpp)

sourceCpp(
   code = '
   #include<Rcpp.h>
   using namespace Rcpp;

   // [[Rcpp::export]]
   NumericVector zeroindex() {
     NumericVector zerosize(0);

     Rcout << zerosize[0] << std::endl;

     return zerosize;
   }
   '
)

zeroindex()
```

On R-release and on previous builds, this returns something like:

```
6.92674e-310
numeric(0)
```

But on current R-devel containers:

```

  *** caught segfault ***

address 0x1, cause 'memory not mapped'



Traceback:

  1: .Call(<pointer: 0x7fa9369c7930>)

  2: zeroindex()



Possible actions:

1: abort (with core dump, if enabled)

2: normal R exit

3: exit R without saving workspace

4: exit R saving workspace
```

It was easy enough to write a catch for the zero-size vector, however I�m 
wondering why the discrepancy between R-devel and previous versions?

Best,
-DMC

        [[alternative HTML version deleted]]


______________________________________________
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

--
Dr. Benjamin Bolker
Professor, Mathematics & Statistics and Biology, McMaster University
Director, School of Computational Science and Engineering
(Acting) Graduate chair, Mathematics & Statistics
> E-mail is sent at my convenience; I don't expect replies outside of working hours.

______________________________________________
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

Reply via email to