[Rd] Accessors returning (void *) 1 for zero-length vectors
Iñaki Ucar
|uc@r @end|ng |rom |edor@project@org
Sat Mar 28 11:19:03 CET 2026
Hi,
We were recently bitten by this [1] (see [2]), when an Rcpp user tried
to std::copy() a vector that may be of length zero and got an UB error
due to misaligned memory. Returning (void *) 1 seems like a very odd
choice to me. The comment suggests that this was a workaround for
Matrix. Wouldn't it be wiser to just fix Matrix and return NULL
instead, which is expected and easier to check and to handle?
[1] https://github.com/wch/r-source/commit/d00ce14c27db627d8644cce8551b792362cc46bf
[2] https://github.com/RcppCore/Rcpp/issues/1461
Best,
--
Iñaki Úcar
More information about the R-devel
mailing list