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

clang sanitizers incorrectly catching integer overflow

Say my size_type is uint64_t, and I have the following loop (where sz is of size_type too) for ( size_type i= 0; i < sz; ++i ) { //something if ( i+1 == sz ) { //<-- here /// } } Now when compiling this with flags…
Ilonpilaaja
  • 1,169
  • 2
  • 15
  • 26
3
votes
1 answer

clang sanitizer callback on error

Is it possible to set some sort of a callback, which will be called when clang sanitizers find an error? I need to print some useful information, such as - test name. P.S. Tests are kept/stored as XML files, not in C++, that is why stack trace won't…
willir
  • 599
  • 1
  • 4
  • 15
3
votes
1 answer

Enable AddressSanitizer by default in gcc

To be able to debug and fuzz a whole Linux distribution, I would like to set ASAN (AddressSanitizer, https://en.wikipedia.org/wiki/AddressSanitizer) as default option to gcc. So normally to achieve what I want, generally, I set the following…
VP.
  • 5,122
  • 6
  • 46
  • 71
3
votes
1 answer

Cannot find -lasan and libasan_preinit.o

When I use -fsanitize=address to link some object into a binary, g++ says the two lib in the title do not exist. My g++ version is: $ /opt/rh/devtoolset-2/root/usr/bin/g++ -v Using built-in specs. …
zuanyg
  • 71
  • 1
  • 1
  • 5
3
votes
1 answer

Additional output from program built with the UB sanitizer of Clang

On travis CI where I use clang version 3.4 (tags/RELEASE_34/final) which is already installed, I build my code with this: clang++ main.cpp -m64 -fsanitize=undefined -Werror -std=c++98 -pedantic -pedantic-errors -fvisibility=hidden -fstrict-aliasing…
onqtam
  • 4,356
  • 2
  • 28
  • 50
3
votes
1 answer

std::vector> push_back gives heap-buffer-overflow

I am trying to solve hackerrank's even tree task with the following piece of code to read the input (std::cin replaced with custom string data to have input and program code in one place here): #include #include #include…
Patryk
  • 22,602
  • 44
  • 128
  • 244
3
votes
2 answers

Address sanitizer failure

I'm using gcc and clang-embedded sanitizers for a little, including address sanitizer. And things work pretty well, but on next demo code I get no output related to a error despite it is there (to be more precise -- no output at all): #include…
Alexander Sergeyev
  • 922
  • 10
  • 19
2
votes
0 answers

How to integrate sanitizer report with gtest and/or Jenkins

I have some multi platform project and address sanitizer found couple issues when running gtest unit tests (issues are from dependencies which where not build with sanitizer). Here is how end of gtest report looks like in console (stdout and stderr…
Marek R
  • 32,568
  • 6
  • 55
  • 140
2
votes
2 answers

Warning: null destination pointer [-Wformat-overflow=] with GCC 11.2.1

Here is my code: #include #include int main() { char *str = new char[64] ; std::sprintf(str, "msg: %s", "hello world") ; std::cout << str << std::endl ; delete [] str ; return 0 ; } With GCC 11.2.1, using…
2
votes
2 answers

How to set ASAN_OPTIONS to CMake managed projects in CLion

I'm trying to use Google sanitizers https://www.jetbrains.com/help/clion/google-sanitizers.html on my CMake project using CLion. I need to pass ASAN_OPTIONS=detect_container_overflow=0 environment variable so that Google sanitizers can pass on the…
2
votes
1 answer

Why LLVM's leak sanitizer not working when using with other sanitizers enabled

I was trying to find a memory leak from a simple program: #include #include #include #include void parse(const char* input) { // Goal: parse out a string between brackets // (e.g. " [target…
Jacket
  • 23
  • 4
2
votes
1 answer

What is the difference between -fsanitize-coverage=trace-pc and trace-pc-guard?

Recently I have been studying the Clang sanitizer. I find the flag -fsanitize-coverage can be trace-pc or trace-pc-guard. According to the official document(Tracing PCs with guards, Tracing PCs), both can insert stub…
SeekaMoon
  • 21
  • 2
2
votes
0 answers

undefined reference to `__dynamic_cast' when using sanitize=vptr

I build vfptr.cpp with fsanitize=vptr to an static file. It has errors messages about "undefined reference to __dynamic_cast". Both g++7.4.0 and g++11.0.0 have the problem. Is it reasonable for using sanitizer=vptr? vptr.cpp struct A { virtual…
eddie kuo
  • 716
  • 1
  • 5
  • 13
2
votes
0 answers

Memory sanitizer false positive on centos 7 but not on other platform

my test code is the following: #include #include int main() { std::string mylongstring("This is a test string"); std::cout << mylongstring << std::endl; } and I compile with the latest clang, using a GCC 7.2…
hassec
  • 686
  • 4
  • 18
2
votes
2 answers

Bazel rule is missing dependency for clang's sanitize-blacklist

I'm trying to add ASAN sanitize to our project which uses Bazel and stuck with the following problem. I've added blacklist for sanitize in our bazel.rc build:asan --copt -fsanitize=address build:asan --linkopt -fsanitize=address build:asan --copt…