UndefinedBehaviorSanitizer
The UndefinedBehaviorSanitizer (ubsan) checks for undefined behaviour.
Checks supported:
alignment
- use of misaligned pointerbool
- loading a bool which is neither true or falsebounds
- out of bounds indexingenum
- loading an enum with an invalid valuefloat-cast-overflow
- cast from float to int outside of the integer's rangefloat-divide-by-zero
- floating point division by zerointeger-divide-by-zero
- integer division by zerononnull-attribute
- passingNULL
to an argument marked[[non-null]]
null
- dereferencing a null pointerobject-size
- using bytes that are not occupied by an objectpointer-overflow
- overflowing a pointer through pointer arithmeticreturn
- reaching the end of a non-void function without returning a valuereturns-nonnull-attribute
- returningNULL
from a[[non-null]]
functionshift
- shifting by more than the width of the type, shifting by a negative value, or shifting a negative valuesigned-integer-overflow
- overflowing a signed integer by addition, subtraction, multiplication or division/modulounreachable
- unreachable code reachedvla-bound
- variable-length array with a zero or negative bound
See the Clang documentation for UBSan for further details.
Building & Usage
Both arm-none-eabi-gcc
and armclang
are supported.
Specific checks can be enabled by linking the code to be instrumented to the target iotsdk-sanitizers-ubsan-${CHECK}
. Alternatively all of the checks can be enabled by linking to the target iotsdk-sanitizers-ubsan
. Otherwise, build as normal with CMAKE_BUILD_TYPE=Debug
.