Hello, I am getting a UBSAN-clang failure on my package hutilscpp (<https://github.com/HughParsonage/hutilscpp>). However I cannot reproduce the error on rhub, nor can I see an obvious problem with the code. (Though obviously there is something wrong.)
The testthat.Rout log from CRAN reads (relevantly): > test_check("hutilscpp") /data/gannet/ripley/R/test-clang/Rcpp/include/Rcpp/internal/caster.h:30:25: runtime error: nan is outside the range of representable values of type 'long' #0 0x7f817412275e in long Rcpp::internal::caster<double, long>(double) /data/gannet/ripley/R/test-clang/Rcpp/include/Rcpp/internal/caster.h:30:25 #1 0x7f817412275e in long Rcpp::internal::primitive_as<long>(SEXPREC*) /data/gannet/ripley/R/test-clang/Rcpp/include/Rcpp/as.h:39:21 #2 0x7f81740f9a50 in long Rcpp::internal::as<long>(SEXPREC*, Rcpp::traits::r_type_primitive_tag) /data/gannet/ripley/R/test-clang/Rcpp/include/Rcpp/as.h:44:20 #3 0x7f81740f9a50 in long Rcpp::as<long>(SEXPREC*) /data/gannet/ripley/R/test-clang/Rcpp/include/Rcpp/as.h:152:16 #4 0x7f81740f9a50 in Rcpp::InputParameter<long>::operator long() /data/gannet/ripley/R/test-clang/Rcpp/include/Rcpp/InputParameter.h:34:38 #5 0x7f81740f9a50 in _hutilscpp_do_which_first__ /data/gannet/ripley/R/packages/tests-clang-SAN/hutilscpp/src/RcppExports.cpp:647:65 #6 0x6e187d in R_doDotCall /data/gannet/ripley/R/svn/R-devel/src/main/dotcode.c:629:17 #7 0x844c13 in bcEval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:7677:21 #8 0x828ab9 in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:727:8 The RcppExports.cpp 647:65 refers to the commented line starting "rcpp_result_gen" below // do_which_first__ R_xlen_t do_which_first__(SEXP x, int op, SEXP y, R_xlen_t nx, R_xlen_t ny, int y1i, int y2i, double y1d, double y2d); RcppExport SEXP _hutilscpp_do_which_first__(SEXP xSEXP, SEXP opSEXP, SEXP ySEXP, SEXP nxSEXP, SEXP nySEXP, SEXP y1iSEXP, SEXP y2iSEXP, SEXP y1dSEXP, SEXP y2dSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::traits::input_parameter< SEXP >::type x(xSEXP); Rcpp::traits::input_parameter< int >::type op(opSEXP); Rcpp::traits::input_parameter< SEXP >::type y(ySEXP); Rcpp::traits::input_parameter< R_xlen_t >::type nx(nxSEXP); Rcpp::traits::input_parameter< R_xlen_t >::type ny(nySEXP); Rcpp::traits::input_parameter< int >::type y1i(y1iSEXP); Rcpp::traits::input_parameter< int >::type y2i(y2iSEXP); Rcpp::traits::input_parameter< double >::type y1d(y1dSEXP); Rcpp::traits::input_parameter< double >::type y2d(y2dSEXP); rcpp_result_gen = Rcpp::wrap(do_which_first__(x, op, y, nx, ny, y1i, y2i, y1d, y2d)); // line 647, column 65 is between nx and ny return rcpp_result_gen; END_RCPP } The ny R_xlen_t value is used in a switch statement in the C++ code. My attempt to fix this code was to limit the values of ny to 1, 2, or 3 before being passed to do_which_first__(). However, since I was not able to reproduce the UBSAN error on rhub I'm not sure if this fix is successful. I would prefer not to submit a package before being completely sure the UBSAN error has been resolved. Thank you for any help, Hugh. ______________________________________________ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel