Re: [Rcpp-devel] Zero length vectors in R

2020-06-10 Thread Dirk Eddelbuettel
On 10 June 2020 at 01:21, Leonardo Silvestri wrote: | The discussion you mention is most likely relevant here - other people | more versed than me in valgrind and R's memory allocation could probably | attest to that. | | Another idea to detect these errors would be to create a modified Rcpp |

Re: [Rcpp-devel] Zero length vectors in R

2020-06-10 Thread Simon Urbanek
Toby, Rcpp simply calls allocVector() so regular R rules apply. R's SEXP can hold vectors up to length 1 inside without additional allocations*, therefore from memory management perspective writes to the first element of a 0-length vector are not invalid. The valgrind instrumentation of R doesn

Re: [Rcpp-devel] Zero length vectors in R

2020-06-09 Thread Leonardo Silvestri
Hi Toby, OK, I see better now what you are trying to do. The discussion you mention is most likely relevant here - other people more versed than me in valgrind and R's memory allocation could probably attest to that. Another idea to detect these errors would be to create a modified Rcpp pac

Re: [Rcpp-devel] Zero length vectors in R

2020-06-09 Thread Toby Hocking
Hi Leonardo thanks for the help. For context, we are trying to fuzz test Rcpp packages, so we are throwing random sized vectors at Rcpp functions which have been written by others. We want to be able to detect when these Rcpp functions have memory read/write issues (e.g. reading the first element o

Re: [Rcpp-devel] Zero length vectors in R

2020-06-08 Thread Leonardo Silvestri
Yes, there is an underlying pointer. You can simply test 'max_segments.size()' to see if you are allowed to dereference that first element or not. If you're interested in the exact R representation of vectors at C-level, read R Internals (https://cran.r-project.org/doc/manuals/r-release/R-in

[Rcpp-devel] Zero length vectors in R

2020-06-08 Thread Akhila Chowdary Kolla
Hello everyone, I am trying to test a package binsegRcpp. I pass the size of max_segments vector as zero it doesn't throw any segfault when I am trying to access the zeroth index element. Instead gives a garbage value or error like negative length vectors not allowed. Rcpp::List rcpp_binseg_normal