sanitizer

Memory Sanitizer

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-27 06:08:45
问题 I am playing around with Memory Sanitizer with Clang 3.7.0 on Ubuntu 14.04. The following code does work perfectly: #include <cstdio> int main() { double ans; printf("Hello World: %f\n", ans); return 0; } when compiled with clang++ -g -O1 -fsanitize=memory -fsanitize-memory-track-origins=2 -fomit-frame-pointer sanitize.cpp -o sanitize I was expecting an error. Doesn't Memory Sanitizer catch the fact that ans was not initialized? Thanks for your help. 回答1: From the clang santitizer

AddressSanitizer blacklist in c++ not working

允我心安 提交于 2020-02-24 09:10:08
问题 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 <stdlib.h> void bad_foo() { int *a = (int*)malloc(40); a[10] = 1; } int main() { bad_foo(); } build % clang -fsanitize=address -fsanitize-blacklist=suppress.txt foo.c ; ./a.out Exit code: 0 But as soon as I use clang++ , its ignored. build % cp foo.c

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

最后都变了- 提交于 2019-12-28 06:28:29
问题 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++ -fsanitize=float-divide-by-zero -std=c++11 -stdlib=libc++ -c source.cpp -o osan and I also compile a "normal" version of my object without using the sanitizer clang++ -std=c++11 -stdlib=libc++ -c source.cpp -o onorm I was expecting some verbose output, or some error

How can I know if Leak Sanitizer is enabled at compile time?

点点圈 提交于 2019-12-23 15:51:06
问题 The GCC and Clang compilers both have support for LeakSanitizer which helps finding memory leaks in C programs. Sometimes a memory leak is unavoidable (because it is being tested in a test suite for example). Such memory can be annotated using the Leak Sanitizer interface: #include <sanitizer/lsan_interface.h> void *p = create_new_object(); __lsan_ignore_object(p); This will however break on compilers that do not support LSan. In Address Sanitizer, this construct can be used to detect the

Gcc thread sanitizer false positive only for debug info flag

萝らか妹 提交于 2019-12-22 12:51:03
问题 I am having a problem with Gcc's thread sanitizer that I cannot find on their bugzilla or on stackoverflow so I am unsure if I am missing something or if this really is a bug. If I create a main.cpp file containing: #include <thread> int main(){ std::thread t([](){}); t.join(); return 0;} Now if I compile it using: g++-4.9.2 -std=c++1y -fsanitize=thread -fPIE -pie -o TestProgram main.cpp Running the resulting executable does not yield any problem. Yet if I add the debug info flag: g++-4.9.2

How to generate core dump on AddressSanitizer error

≯℡__Kan透↙ 提交于 2019-12-21 19:56:46
问题 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? 回答1: You need to set environment variable to request coredumps export ASAN_OPTIONS=abort_on_error=1 This should really be default but due to historic reasons ASan just exits with non-zero error code instead. On 64-bit systems you might need to add export ASAN_OPTIONS=...:disable

Misaligned address using virtual inheritance

女生的网名这么多〃 提交于 2019-12-12 07:15:42
问题 The following apparently valid code produces a misaligned address runtime error using the UndefinedBehaviorSanitizer sanitiser. #include <memory> #include <functional> struct A{ std::function<void()> data; // seems to occur only if data is a std::function } ; struct B{ char data; // occurs only if B contains a member variable }; struct C:public virtual A,public B{ }; struct D:public virtual C{ }; void test(){ std::make_shared<D>(); } int main(){ test(); return 0; } Compiling and executing on

Address sanitizer failure

心已入冬 提交于 2019-12-12 04:56:33
问题 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 <string> #include <iostream> using std::string; using std::cout; class Foo { string _member; public: Foo(): _member("just a string") {} const string& get() const { return _member; } }; const string& bar() { // returning reference to a temp object on

Gcc thread sanitizer false positive only for debug info flag

折月煮酒 提交于 2019-12-06 10:52:15
I am having a problem with Gcc's thread sanitizer that I cannot find on their bugzilla or on stackoverflow so I am unsure if I am missing something or if this really is a bug. If I create a main.cpp file containing: #include <thread> int main(){ std::thread t([](){}); t.join(); return 0;} Now if I compile it using: g++-4.9.2 -std=c++1y -fsanitize=thread -fPIE -pie -o TestProgram main.cpp Running the resulting executable does not yield any problem. Yet if I add the debug info flag: g++-4.9.2 -std=c++1y -fsanitize=thread -g -fPIE -pie -o TestProgram main.cpp then the thread sanitizer detects a

Why can't clang enable all sanitizers?

此生再无相见时 提交于 2019-12-05 13:18:46
问题 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 1 clang: error: invalid argument '-fsanitize=address' not allowed with '-fsanitize=memory' It's not a big deal, but when I run my unit tests, it takes longer than it should, because I have create multiple binaries for the same tests, and run each of them