[Rcpp-devel] Rcpp::wrap seg fault (when called with a NULL pointer)

Dirk Eddelbuettel edd at debian.org
Tue May 24 18:21:29 CEST 2011

On 24 May 2011 at 17:29, Christoph Bergmeir wrote:
| Hi,
| of course it's your decision, but I personally think that adding the check to the wrapper is a good idea. For now, I added the check everywhere in my code where I use a const char* with Rcpp::wrap.

Please try SVN revision 3030 which is now resilient to this particular case
of NULL:

edd at max:~$ r -p /tmp/nil.r 
Loading required package: inline
Loading required package: methods
edd at max:~$ cat /tmp/nil.r 

fun <- cxxfunction(signature(),plugin="Rcpp",body='
  const char *ret = NULL;
  return Rcpp::wrap(ret);

edd at max:~$ 

As I joked earlier, it won't help the next time NULL comes hiding as the
payload of another pointer, but at least const char* is now covered. I also
added two quick unit tests.

Thanks for alerting us to this. Segfaults are after all almost always bad.


Gauss once played himself in a zero-sum game and won $50.
                      -- #11 at http://www.gaussfacts.com

More information about the Rcpp-devel mailing list