<div dir="ltr">Hello everyone,<div><br></div><div>I am trying to test a package binsegRcpp. I pass the size of max_segments vector as zero it doesn't throw any segfault when I am trying to access the zeroth index element. Instead gives a garbage value or error like negative length vectors not allowed.</div><div><table style="border-spacing:0px;border-collapse:collapse;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";font-size:14px"><tbody style="box-sizing:border-box"><tr style="box-sizing:border-box"><td id="m_8130613182187243996gmail-LC7" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap">Rcpp::List rcpp_binseg_normal</td></tr><tr style="box-sizing:border-box"><td id="m_8130613182187243996gmail-L8" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;line-height:20px;color:rgba(27,31,35,0.3);text-align:right;white-space:nowrap;vertical-align:top"></td><td id="m_8130613182187243996gmail-LC8" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap">(<span style="box-sizing:border-box;color:rgb(215,58,73)">const</span> Rcpp::NumericVector data_vec,</td></tr><tr style="box-sizing:border-box"><td id="m_8130613182187243996gmail-L9" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;line-height:20px;color:rgba(27,31,35,0.3);text-align:right;white-space:nowrap;vertical-align:top"></td><td id="m_8130613182187243996gmail-LC9" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap"> <span style="box-sizing:border-box;color:rgb(215,58,73)">const</span> Rcpp::IntegerVector max_segments) {</td></tr><tr style="box-sizing:border-box"><td id="m_8130613182187243996gmail-L10" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;line-height:20px;color:rgba(27,31,35,0.3);text-align:right;white-space:nowrap;vertical-align:top"></td><td id="m_8130613182187243996gmail-LC10" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap">  <span style="box-sizing:border-box;color:rgb(215,58,73)">int</span> kmax = max_segments[<span style="box-sizing:border-box;color:rgb(0,92,197)">0</span>];</td></tr></tbody></table></div><div> }<br></div><div>Link to the package: <a href="https://github.com/tdhock/binsegRcpp/blob/master/src/rcpp_interface.cpp">https://github.com/tdhock/binsegRcpp/blob/master/src/rcpp_interface.cpp</a></div><div><br></div><div>How is a zero-length vector represented in R? Does it still store a pointer to some location?</div><div>If so Is there a way to get this segfault detected. I tried using rhub::check it doesn't give any error. I tried using sanitizers as well still no luck.</div><div>Can someone please suggest a way to detect this in R.</div><div><br></div><div>Thanks</div><div><span style="background-color:transparent;color:rgb(0,0,0);font-family:Arial;font-size:11pt;white-space:pre-wrap"><br></span></div><div><br></div><div><br></div></div>