<div dir="ltr">Another thing confused me is the segfault only happens when the IntegerVector is significantly long.<div><br></div><div>Best,</div><div><br></div><div>KK</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jan 30, 2016 at 2:57 AM, Kevin Ushey <span dir="ltr"><<a href="mailto:kevinushey@gmail.com" target="_blank">kevinushey@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hmm, I have one thought: we try to re-use the indices from an<br>
IntegerVector, but the type here is actually a sugar type:<br>
<span class=""><br>
    Rcpp::SubsetProxy<13, Rcpp::PreserveStorage, 13, true,<br>
    Rcpp::sugar::Minus_Vector_Primitive<13, true, Rcpp::Vector<13,<br>
</span>    Rcpp::PreserveStorage> > >::get_vec (this=<optimized out>)<br>
<br>
Ie, we access the indices with `INTEGER(x)`, but perhaps those indices<br>
have not actually been properly materialized when we attempt to<br>
perform the subset?<br>
<br>
But then, a simple test case with `x[y - 1]` with `x` and `y` both<br>
being integer vectors seems to work just fine. So I am a bit confused.<br>
<div class="HOEnZb"><div class="h5"><br>
On Fri, Jan 29, 2016 at 3:16 PM, Dirk Eddelbuettel <<a href="mailto:edd@debian.org">edd@debian.org</a>> wrote:<br>
><br>
> On 29 January 2016 at 17:55, Qiang Kou wrote:<br>
> | Hi, Paul, can you try my fork of Rcpp? You can install it by the line below:<br>
> |<br>
> | devtools::install_github("thirdwing/Rcpp", ref = "subsetter")<br>
> |<br>
> | This fixed the segfault on my Ubuntu machine.<br>
><br>
> Yay. Nice work!<br>
><br>
> | The difference can be found from [1].<br>
><br>
> Nice and concise.<br>
><br>
> | In subsetter, if an IntegerVector passed in, we will try to reuse it. This led<br>
> | to a segfault in this case, which I don't know why.<br>
> |<br>
> | Dirk and Kevin, do you have any thoughts on it?<br>
><br>
> Not really, but happy to give this the full reverse-dependency check<br>
> treatment so that we can merge it.<br>
><br>
> Dirk<br>
><br>
><br>
> | Best wishes,<br>
> |<br>
> | KK<br>
> |<br>
> | [1] <a href="https://github.com/thirdwing/Rcpp/commit/" rel="noreferrer" target="_blank">https://github.com/thirdwing/Rcpp/commit/</a><br>
> | 216c5220bcb84778a656b3496d0f1803b973ef61<br>
> |<br>
> |<br>
> | On Fri, Jan 29, 2016 at 3:00 PM, Qiang Kou <<a href="mailto:qkou@umail.iu.edu">qkou@umail.iu.edu</a>> wrote:<br>
> |<br>
> |<br>
> |     Hi, Kevin, I was also trying to track this down yesterday.<br>
> |<br>
> |     From the debugging info below, indices_n is not equal to length of indices,<br>
> |     which I don't quite understand.<br>
> |<br>
> |     Program received signal SIGSEGV, Segmentation fault.<br>
> |<br>
> |     0x00007ffff2ed5c4e in Rcpp::SubsetProxy<13, Rcpp::PreserveStorage, 13,<br>
> |     true, Rcpp::sugar::Minus_Vector_Primitive<13, true, Rcpp::Vector<13,<br>
> |     Rcpp::PreserveStorage> > >::get_vec (this=this@entry=0x7fffffff79a0)<br>
> |<br>
> |         at /usr/local/lib/R/site-library/Rcpp/include/Rcpp/vector/<br>
> |     Subsetter.h:200<br>
> |<br>
> |     199             output[i] = lhs[ indices[i] ];<br>
> |<br>
> |     (gdb) p i<br>
> |<br>
> |     $1 = 33622<br>
> |<br>
> |     (gdb) p indices[i]<br>
> |<br>
> |     Cannot access memory at address 0x34c6e000<br>
> |<br>
> |     (gdb) p indices_n<br>
> |<br>
> |     $2 = 9594546<br>
> |<br>
> |<br>
> |     On Fri, Jan 29, 2016 at 2:29 PM, Dirk Eddelbuettel <<a href="mailto:edd@debian.org">edd@debian.org</a>> wrote:<br>
> |<br>
> |<br>
> |         On 29 January 2016 at 11:27, Kevin Ushey wrote:<br>
> |         | When I add some debug printing to the associated subscripting line<br>
> |         | (<a href="https://github.com/awalker89/openxlsx/blob/" rel="noreferrer" target="_blank">https://github.com/awalker89/openxlsx/blob/</a><br>
> |         b92bb3acdd6ea759be928c298c6faeef2f26fa3e/src/cppFunctions.cpp#L2608),<br>
> |         | I see:<br>
> |         |<br>
> |         |    colNumbers.size(): 98,03,150<br>
> |         |    charCols.size(): 95,94,546<br>
> |         |<br>
> |         | It looks to me like the package is erroneously attempting to subset<br>
> |         | vectors of different sizes, causing out-of-bounds reads.<br>
> |<br>
> |         Nice work.<br>
> |<br>
> |         | Unfortunately, Rcpp is not detecting or warning about this...<br>
> |         |<br>
> |         | Either way, I believe this is a bug in the openxlsx package, but Rcpp<br>
> |         | should be checking / reporting this.<br>
> |<br>
> |         With (Rcpp)Armadillo you do have an option of turning this on/off. With<br>
> |         Rcpp<br>
> |         alone not quite.<br>
> |<br>
> |         Dirk<br>
> |<br>
> |         --<br>
> |         <a href="http://dirk.eddelbuettel.com" rel="noreferrer" target="_blank">http://dirk.eddelbuettel.com</a> | @eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a><br>
> |         _______________________________________________<br>
> |         Rcpp-devel mailing list<br>
> |         <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
> |         <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" rel="noreferrer" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
> |<br>
> |<br>
> |<br>
> |<br>
> |     --<br>
> |     Qiang Kou<br>
> |     <a href="mailto:qkou@umail.iu.edu">qkou@umail.iu.edu</a><br>
> |     School of Informatics and Computing, Indiana University<br>
> |<br>
> |<br>
> |<br>
> |<br>
> |<br>
> | --<br>
> | Qiang Kou<br>
> | <a href="mailto:qkou@umail.iu.edu">qkou@umail.iu.edu</a><br>
> | School of Informatics and Computing, Indiana University<br>
> |<br>
><br>
> --<br>
> <a href="http://dirk.eddelbuettel.com" rel="noreferrer" target="_blank">http://dirk.eddelbuettel.com</a> | @eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">Qiang Kou<div><a href="mailto:qkou@umail.iu.edu" target="_blank">qkou@umail.iu.edu</a><br><div>School of Informatics and Computing, Indiana University</div><div><br></div></div></div></div>
</div>