Questions tagged [sanitizer]

Sanitizers are a compiler feature supported by Clang and GCC for instrumenting programs to do dynamic analysis and catch many classes of bugs at runtime.

Sanitizers are a compiler feature supported by Clang and GCC for instrumenting programs to do dynamic analysis. There are sanitizers to detect many issues, including many C and C++ "undefined behaviors", signed integer arithmetic overflow, memory allocation errors, use of uninitialized memory, and data races between threads.

These checks can be enabled at compile time using the -fsanitize= option (for example, -fsanitize=address).

The following sanitizers are supported:

More information on the sanitizers development can be found at http://compiler-rt.llvm.org/.

The current list of supported options can be found in the compiler documentation:

120 questions
72
votes
10 answers

A C++ implementation that detects undefined behavior?

A huge number of operations in C++ result in undefined behavior, where the spec is completely mute about what the program's behavior ought to be and allows for anything to happen. Because of this, there are all sorts of cases where people have code…
templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
45
votes
2 answers

What features does gcc-4.9 Undefined Behavior Sanitizer have?

In gcc-4.9 changes it says: UndefinedBehaviorSanitizer (ubsan), a fast undefined behavior detector, has been added and can be enabled via -fsanitize=undefined. Various computations will be instrumented to detect undefined behavior at runtime.…
user1508519
44
votes
3 answers

How can I break on UBSan reports in gdb and continue?

Recent versions of GCC and Clang feature Undefined Behavior Sanitizer (UBSan) which is a compile flag (-fsanitize=undefined) that adds runtime instrumentation code. On errors, a warning such as this one is shown: packet-ber.c:1917:23: runtime…
Lekensteyn
  • 64,486
  • 22
  • 159
  • 192
33
votes
2 answers

Why can't clang enable all sanitizers?

Clang has various sanitizers that can be turned on to catch problems at runtime. However, there are some sanitizers that I can't use together. Why is that? clang++-3.9 -std=c++1z -g -fsanitize=memory -fsanitize=address -o main main.cpp …
Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
27
votes
3 answers

Clang Address Sanitizer on OS X

I would like to use clang address sanitizer on OSX Mountain Lion, because Valgrind have problems with memory check on this platform. But when I had the -fsanitize=address during the compilation time (like I see on this page :…
Guillaume
  • 8,741
  • 11
  • 49
  • 62
25
votes
3 answers

Undefined behavior (according to clang -fsanitize=integer) on libstdc++ std::random due to negative index on Mersenne Twister engine

I'm using clang++ 10 on Ubuntu 20.04 LTS, with -fsanitize-undefined-trap-on-error -fsanitize=address,undefined,nullability,implicit-integer-truncation,implicit-integer-arithmetic-value-change,implicit-conversion,integer My code is generating random…
Something Something
  • 3,999
  • 1
  • 6
  • 21
17
votes
1 answer

How to enable sanitizers in QMake?

How do I enable usage of sanitizers in QMake's .pro files? I found several ressources that modify QMAKE_CXXFLAGS themselves but the introductory blogpost says: It is scheduled for the dev branch (Qt 5.2) because it’s a new feature, but you should…
16
votes
1 answer

std::string_view on temporary string - catch by ASan

This is dangling pointer|reference example: #include #include #include std::string foo() { return "test"; } int main() { std::string_view bar = foo(); // bar is pointed to destructed string std::cout…
vladon
  • 8,158
  • 2
  • 47
  • 91
16
votes
2 answers

How I'm supposed to use the sanitizer in clang?

I'm sorry if this is a uber-easy concept, but I find hard to acquire the right mindset in order to correctly use the sanitizer provided by clang. float foo(float f) { return (f / 0); } I compile this small snippet with clang++…
user2485710
  • 9,451
  • 13
  • 58
  • 102
13
votes
1 answer

AddressSanitizer, What do these terms mean?

So I'm using the AddressSanitizer. But it uses some dense terms when describing the problem. Shadow bytes around the buggy address: 0x0c067fff7fb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c067fff7fc0: 00 00 00 00 00 00 00 00 00 00 00…
Tarick Welling
  • 3,119
  • 3
  • 19
  • 44
13
votes
1 answer

How to generate core dump on AddressSanitizer error

I compiled my code like this to enable Asan: g++ -O0 -g -fsanitize=address -fno-omit-frame-pointer but it never generates a core dump so that I can later examine the details of the error. How can I generate it?
wsy
  • 219
  • 4
  • 8
13
votes
1 answer

using address sanitizer with OpenCV

I'm trying to use Google's Address Sanitizer with a CUDA project, more precisely with OpenCV cuda functions. However I got an 'out of memory' error on the first cuda call. OpenCV Error: Gpu API call (out of memory) in getDevice, file…
Pluc
  • 901
  • 8
  • 21
12
votes
1 answer

Is this code really undefined, as Clang seems to indicate?

I switched on -fsanitize=undefined on my project which uses Catch, the unit testing library. One line from Catch was signalled as causing undefined behaviour by this flag. I managed to make an isolated example: #include #include…
Tobias
  • 924
  • 9
  • 23
11
votes
1 answer

Address Sanitizer Warning

For a few days now I get the following issue when starting up the Address Sanitizer within Xcode 7.3. The error messages printed to the Xcode console when the Sanitizer found an issue (that was actually suppressed by a file): ==13392==WARNING:…
HelloWorld
  • 2,392
  • 3
  • 31
  • 68
9
votes
2 answers

AddressSanitizer Suppression

I am trying to suppress a warning from the address sanitizer in clang/gcc My source file looks like this: int foo(){ double bar[] = {7,8}; return bar[3]; } int main(){ return foo(); } and obviously there is an overflow at line 3. the…
user1928546
  • 143
  • 1
  • 1
  • 5
1
2 3 4 5 6 7 8