CppCon 2014: Kostya Serebryany "Sanitize your C++ code"

CppCon · 16K views · 2014 · 1:01:51

Open on YouTube

Testing, debugging & developer toolsC, C++, Rust, Go & systems languagestalk

Why Stack Overflow recommends it

Stack Overflow users link it when answering questions about finding memory errors, leaks and uninitialized variables in C++, as an explanation of how the sanitizers work and why they beat tools like valgrind.

Recommended by 2 people across 2 different months, 2015 to 2017.

What it is

A CppCon 2014 talk by Google engineer Kostya Serebryany, who works on AddressSanitizer and ThreadSanitizer. It explains how the Clang and GCC sanitizers (Address, Thread, Memory, UndefinedBehavior) work, how to use them on small programs, and how they are deployed in large projects.

What people said

Recommends Nobody moving away from SE · 2015-02 · Stack Overflow · on “Memory Leak Detectors Working Principle”

So far the (address) sanitizers have not been mentioned. This talk [this video] from CppCon14 gives a good summary of how they work.

Recommends Jurasic · 2016-02 · Stack Overflow · on “Easy way find uninitialized member variables”

In case of using clang compiler you can try memory sanitizer: [LINK] It perform dynamic checking and has significantly less overhead compared to valgrind. There is nice presentation from the author on cppcon2014 [this video]

Cites Sitesh · 2017-11 · Stack Overflow · on “How to track down a "double free or corruption" error”

With modern C++ compilers you can use sanitizers to track. Sample example : My program: $cat d_free.cxx #include<iostream> using namespace std; int main() { int * i = new int(); delete i; //i = NULL; delete i; } Compile with address sanitizers : # g++-7.1 d_free.cxx -Wall -Werror -fsanitize=address -g Execute : # ./a.out ================================================================= ==4836==ERROR: AddressSanitizer: attempting double-free on 0x602000000010 in thread T0: #0 0x7f35b2d7b3c8 in operator delete(void*, unsigned long) /media/sf_shared/gcc-7.1.0/libsanitizer/asan/asan_new_delete.cc:140 #1 0x400b2c in main /media/sf_shared/jkr/cpp/d_free/d_free.cxx:11 #2 0x7f35b2050c04 in __libc_st