How it works...

Google's address sanitizer is a set of modifications to the GCC and LLVM compilers, as well as a set of libraries that must be linked into your application when testing. To accomplish this, we must add the following compiler flags when compiling code for testing (but do not add these flags to production releases):

-fsanitize=address 
-fno-optimize-sibling-calls
-fsanitize-address-use-after-scope
-fno-omit-frame-pointer
-g -O1

The most important flag to pay attention to here is the -fsanitize=address flag, which tells the compiler to enable ASAN. The rest of the flags are required by the sanitizer to function properly, with the most notable flags being -g and -01. The -g flag enables debugging and the -O1 flag sets the optimization level to 1 to provide some performance improvements. Note that once the ASAN tool is enabled, the compiler will automatically attempt to link to the ASAN libraries, which must be present on your machine.

To demonstrate how this sanitizer works, let's look at a few examples.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset