Address Sanitizer

  • Address Sanitizer is a tool for detecting memory errors for C and C++ that is similar to Valgrind and it is available in Xcode.

  • To enable Address Sanitizer in Xcode for a project, select Product > Scheme > Edit Scheme in the menu bar. Then choose Run (on the left) and Diagnostics (at the top) and select the checkbox next to Address Sanitizer.

    xcode address sanitizer.png
  • For example, suppose we create an array with four numbers and incorrectly try to print the last element by using arr[4] instead of arr[3]:

    int arr[] = {183, 203, 280, 281};
    cout << arr[4] << endl;

    Normally, the program would not crash (though it would print some number that we don’t expect). However, by using the Address Sanitizer, we are able to immediately see the line of code that is causing issues.

    xcode address sanitizer array.png
  • See Advanced Debugging and the Address Sanitizer session from Apple’s WWDC (2015) for more details.

results matching ""

    No results matching ""