1. 3
  1. 1

    This post boils down to a one-liner:

    GCC and LLVM sanitizers call a function (__asan_on_error()) when when an error is encounter, allowing us to log it.

    Good to know. But the example is impractical; who is really going to instrument every spot in their program where a sanitizer error could occur?

    Anyway, the LLVM sanitizer already logs very detailed context information when triggered, including the stack trace and (in this case) the offending address and the bounds of the buffer.

    1. 1

      I think you misunderstood the article.

      Good to know. But the example is impractical; who is really going to instrument every spot in their program where a sanitizer error could occur?

      GCC or LLVM.

      You use this hook that they provide to do things like send a notification to your logging framework, aggregate statistics, or do other similar things.

      1. 1

        I understand sanitizers and use the LLVM one all the time!

        My point was that his example uses the callback to log the current index being accessed … which is useful when that specific next line fails, but to make that useful in a real program you’d be adding code all over the place to set “message”.

        Plus, you can already find the array index from the LLVM ASan output, which gives both the offending address and the bounds of the buffer.