[Rcpp-devel] AddressSanitizer: stack-use-after-scope Error

Noah Greifer noah.greifer at gmail.com
Mon Nov 16 20:14:07 CET 2020


Hi Dirk and Kevin,

Thank you for the replies. I was able to find a way to check my code using
the build of R that CRAN used to point out these problems. I asked Uwe and
he recommended I look into R-hub (which I had not encountered before) and
found the package builder <https://builder.r-hub.io/advanced>, which
includes the option to check on "Debian Linux, R-devel, GCC ASAN/UBSAN". I
found that I had two issues: not correctly importing an R function into my
Rcpp code, and using a lambda expression without importing C++11. I was
using an Rcpp equivalent to base::order() as described in the answer to this
SO question
<https://stackoverflow.com/questions/48118248/rcpp-rearrange-a-vector-in-an-order-of-another-vector>.
As a novice, I didn't know that this necessitated C++11. After adding the
correct components to the source code (including adding C++11 to the system
requirements in the Description), I received no errors when using the R-hub
builder. So, I think I can say my problem has been solved. Sorry to have
wasted others' time with this question, but hopefully it will be useful for
posterity.

In short, I wasn't actually looking for help debugging the code, I just
wanted to know a way to check whether my proposed edits had fixed the noted
problems, and I found that solution in the R-hub builder.

Noah

On Mon, Nov 16, 2020 at 1:27 PM Dirk Eddelbuettel <edd at debian.org> wrote:

>
> Hi Noah,
>
> Thanks for posting here.  We'll try to help.
>
> On 15 November 2020 at 18:30, Noah Greifer wrote:
> | In searching for solutions to the problem of being able to check whether
> | the issue in my package remains, I came across this
> | <http://dirk.eddelbuettel.com/code/sanitizers.html> article posted by
> Dirk
> | ("sanitizers: Testing R packages for ASAN and UBSAN errors"). It seems
> like
> | this article is about using sanitizers, which helps you figure out if
> your
> | build of R is able to detect the memory allocation errors I was facing,
> but
> | doesn't give clear instructions on how to set up R to do this. As someone
> | for whom using Rcpp was my first use of programming outside R, the
> | instructions given in the article and in section 4.3 of Writing R
> | Extensions are completely foreign to me and seem to require a deep
> | knowledge of C++.
>
> [ Not quite: `sanitizers` is a package I wrote when facing such ASAN/UBSAN
>   report issues. I noticed that I at times had the additional difficulty of
>   being unable to reproduce such errors when they should have reproduced
> -- so
>   `sanitizers` "merely" regroups some of those errors to ensure the testing
>   procedure you use, these days mostly Docker containers or RHub services,
>   triggers them correctly and hence validates your setup. No more, really.
> ]
>
> | I'm wondering if someone can provide me with a clear procedure on how to
> | check if the memory allocation problem still remains in my package. Thank
> | you.
>
> This is is indeed advanced stuff, and sadly the CRAN maintainers sometimes
> fling it at us. As Kevin said, the best bet really is to distill it into as
> small an example as you can.  That is, in essence, what sanitizers does too
> if you look at its sources.  Once you have a small example, it usually
> becaome feasible / easier to find the solution to _not_ triggering the
> report.  Many of us have found that this is often an underlying programming
> bug in our packages, so as painful as it is when CRAN sticks the finger
> into
> these sores they usually do need fixing.
>
> Dirk
>
> --
> https://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20201116/960e7a2b/attachment.html>


More information about the Rcpp-devel mailing list