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
9
votes
1 answer

Which of the three mutually exclusive Clang sanitizers should I default to?

Clang has a number of sanitizers that enable runtime checks for questionable behavior. Unfortunately, they can't all be enabled at once. It is not possible to combine more than one of the -fsanitize=address, -fsanitize=thread, and…
Maxpm
  • 24,113
  • 33
  • 111
  • 170
9
votes
1 answer

Misaligned address using virtual inheritance

The following apparently valid code produces a misaligned address runtime error using the UndefinedBehaviorSanitizer sanitiser. #include #include struct A{ std::function data; // seems to occur only if data is a…
8
votes
3 answers

Memory Sanitizer

I am playing around with Memory Sanitizer with Clang 3.7.0 on Ubuntu 14.04. The following code does work perfectly: #include int main() { double ans; printf("Hello World: %f\n", ans); return 0; } when compiled with clang++ -g -O1…
InsideLoop
  • 6,063
  • 2
  • 28
  • 55
7
votes
0 answers

-fsanitize=address duplicates inline strings. Is this intended behavior or a compiler issue?

In our codebase we expect that strings only exist once in the compiled binary. I observe that -fsanitize=address can generate duplicated strings in the executable. This breaks our code. The following godbolt example demonstrates the issue…
Thomas m
  • 133
  • 4
7
votes
1 answer

what are the valid sanitizer suppression strings for gcc?

When using sanitizers with gcc one can provide a list of exceptions/suppressions to deal with false positives and such. the suppression file format is poorly documented. Each suppression is of the form name_of_check:path_or_name What are the valid…
6
votes
2 answers

1 << 31 cannot be represented by type 'int'?

Why does -fsanitize=undefined throw runtime error: left shift of 1 by 31 places cannot be represented in type 'int' on this code uint32_t z; z = 1 << 31; ?
Geremia
  • 4,745
  • 37
  • 43
6
votes
1 answer

AddressSanitizer blacklist in c++ not working

I'm trying to get address sanitizer blacklist working in a C++ project but its not working as expected. I tried the example on their website, if I compile with clang, it works fine. build % cat suppress.txt fun:bad_foo build % cat foo.c #include…
Tareq A. Siraj
  • 424
  • 3
  • 9
6
votes
1 answer

clang: -fsanitize=undefined with 128 integer operations (undefined reference to `__muloti4')

In clang, I run into linking error if the Undefined Behavior Sanitizer (-fsanitize=undefined) when the program uses 128 bit integer. The linking errors complain about __muloti4: $ cat example.c __int128_t a; int main (void) { a = a * a; return…
Philipp Claßen
  • 41,306
  • 31
  • 146
  • 239
6
votes
3 answers

How to set ASAN/UBSAN reporting output

I would like to run my unit test suite with -fsanitize=address,undefined and have all sanitizer errors be written to a report.txt file. By default all sanitizer errors get written to stdout, however the software also writes info to stdout so this…
Jeroen Ooms
  • 31,998
  • 35
  • 134
  • 207
6
votes
1 answer

Catching and debugging invalid use of reference to local variable inside moved lambda

I've come across an hard-to-debug situation in one of my real projects where I was accidentally accessing a reference to a local variable inside a lambda that had been moved. The access was being done from another thread, but the moved lambda was…
Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416
6
votes
2 answers

Undefined behavior sanitizer suppression file: failed to parse suppressions

After compiling an application with clang 3.6 using -fsanitize=undefined, I'm trying to start the instrumented program while using a suppression file to ignore some of the errors: UBSAN_OPTIONS="suppressions=ubsan.supp" ./app.exe The suppression…
nucleon
  • 1,128
  • 1
  • 6
  • 19
6
votes
3 answers

Check whether sanitizer like AddressSanitizer is active

I have several versions of a project checkout out and compiled. If I spot an error, I compare the versions to narrow the problem down. Sometimes I enable sanitizers like the AddressSanitizer. If I re-use an executable, I don't remember whether it…
usr1234567
  • 21,601
  • 16
  • 108
  • 128
6
votes
2 answers

Unable to reproduce memory sanitization results from the project's example project

I'm getting exactly the same results from centos7, clang-3.6.1 built from source using a fedora rpm specfile. Ubuntu 14.04, clang-3.4 Using the instructions from the wiki here https://github.com/google/sanitizers/wiki/MemorySanitizerLibcxxHowTo as…
Hal
  • 1,061
  • 7
  • 20
6
votes
3 answers

Configure an autotools project with Clang sanitizers in a static lib configuration?

EDIT: If its TLDR, just skip to the bottom. Its where I ask: How do I configure an autotools project to use a static library? I'm working with a couple of open source libraries, and I'm trying to run their test suite under Clang's sanitizers. To run…
jww
  • 97,681
  • 90
  • 411
  • 885
5
votes
2 answers

Add unique attribute id to each h2-tag with owasp java html sanitizer

I am using owasp-java-html-sanitizer and try to add id-attributes to each h2-tag in my HTML Code, which should be persistent over several page loads but unique for each element on the page(as defined for id-attributes). I tried to count all elements…
Nixen85
  • 1,253
  • 8
  • 24