Closed jwood000 closed 6 years ago
The problem was arising from the following lines of code:
if (IsInteger)
vInt.assign(vNum.begin(), vNum.end());
Before this, vNum
(a vector of doubles) could possibly contain a nan
value. As a result, the code above would trigger undefined behavior as there is no defined conversion from nan
to int
. We rectify this with the following setup:
if (IsInteger) {
for (int i = 0; i < n && IsInteger; ++i)
if (Rcpp::NumericVector::is_na(vNum[i]))
IsInteger = false;
if (IsInteger)
vInt.assign(vNum.begin(), vNum.end());
}
The fix has been confirmed with a clean run from docker with rocker/r-devel-ubsan-clang
.
Many thanks to Brian J. Knaus and Dirk Eddelbuettel for posting excellent articles on this topic:
https://knausb.github.io/2017/06/reproducing-a-clang-ubsan-issue/ https://knausb.github.io/2017/06/running-r-devel-ubsan-clang-in-docker/
https://stackoverflow.com/a/33179049/4408538 https://github.com/rocker-org/r-devel-san-clang http://dirk.eddelbuettel.com/blog/2015/01/18/
OffTopic, how can I test using this docker: rocker/r-devel-ubsan-clang
just drop my built .tar.gz file there and run R CMD check?
thanks
@franzbischoff,
It's a little more involved than that. Those links I posted are great starts.
Personally, it took me a while (about 1.5 weeks) to figure out how to get it running for my specific case. I read quite a bit of documentation and articles before I was able to get it working properly. It still wasn't over. I had to read a dozen more articles/post/documentation on what the output meant.
I have another issue (https://github.com/jwood000/RcppAlgos/issues/8) that goes into this in more detail.
I hope this helps.
Cheers, Joseph
Here is 00check.log
And here is the testthat.Rout