Safety
Go Up to C++ Compiler
Project > Options > Building > C++ Compiler > Safety
Use this dialog box to set C++ compiler safety settings that enable and improve the safety and quality of the source code and application.
Options | Description |
---|---|
Target, Apply, Save |
See Target Options. |
Common items |
Contents
Safety Options
Sanitizers add runtime checking to your application, which can be used to improve the code's correctness and safety.
Safety Options | Description | Compiler switches | ||||||
---|---|---|---|---|---|---|---|---|
bcc32 | bcc32c | bcc64 | bcc64x | |||||
Address sanitizer |
Detects various memory errors, such as use-after-free, double frees, access out of bounds, and more. Attention: See the Using the Address Sanitizer section below.
|
Platform not supported |
Platform not supported |
Platform not supported |
![]() | |||
Undefined behavior sanitizer |
Detects a variety of operations with silent failures or unexpected behavior (not defined in the C++ Standard). Examples include signed integer overflows, bitshifts too wide for the data type, dereferencing invalid pointers, and more. |
Platform not supported |
Platform not supported |
Platform not supported |
![]() |
Using the Address Sanitizer
When building an application with the Address Sanitizer enabled, you must run the application outside the IDE. Running from a command prompt is strongly recommended to avoid seeing the AVs.
When running the application in IDE, the debugger captures access violations related to the work the Address Sanitizer performs. A process will run until the sanitizer finds an error, at which point it will print to the console and terminate (it is safe to continue past these, but they are misleading in that they appear to demonstrate errors). Running from a command window leaves this text onscreen.
By default, UI apps (VCL or FMX) do not have a console, specifically the standard error output. Therefore, if a user runs the app directly:
> myapp.exe
No errors are returned, and instead, the app is terminated. To solve this, change the app to use the console subsystem or pipe the output to a log file (doing so creates stderr) as follows:
myapp 2> asanlog.txt.
or
myapp > asanlog.txt 2>&1
The above redirects both stderr
and stdout
together to the log file.
Address Sanitizer Issue on Windows 11
There is an issue when using the Address Sanitizer on Windows 11. It is not supported as of RAD Studio version 12.3 but will be included in the next release update.
RAD Studio recommends using Address Sanitizers only on Windows 10.