To achieve optimal performance of C/C++, the compiler and OS (Windows, Linux, and macOS) runtime framework do not perform security detection on memory operations. This is where Address Sanitizer (ASan) comes into the picture. ASan is integrated in DevEco Studio to detect C/C++ out-of-bounds addresses, and display error stack details and problematic code lines in FaultLog. For details about the ASan detection principles, see ASan Detection Principles.


"asanEnabled": true

In the module where ASan needs to be enabled, add build parameters to enable ASan instrumentation. Specifically, in the build-profile.json5 file of the module, add the following:
"arguments": "-DOHOS_ENABLE_ASAN=ON"

Leaving this parameter unspecified will not cause errors. However, in this case, aside from a few memory errors that include malloc and free functions, ASan will not be able to detect other memory errors that require instrumentation for detection.
Configure ASAN_OPTIONS to define behavior of ASan at runtime, including setting the detection level, output format, detail level of memory error reports, and more. ASAN_OPTIONS can be configured in the app.json5 file or under Run/Debug Configurations. The configuration in app.json5 takes precedence. If both methods are used, the settings in app.json5 prevail. For details about how to configure ASAN_OPTIONS and common parameters, see Configuring Parameters.
