Skip to content

Add build flag to enable UBSAN in tests#916

Open
cegonse wants to merge 1 commit intoOpenWaterAnalytics:devfrom
cegonse:enable-ubsan-tests
Open

Add build flag to enable UBSAN in tests#916
cegonse wants to merge 1 commit intoOpenWaterAnalytics:devfrom
cegonse:enable-ubsan-tests

Conversation

@cegonse
Copy link
Copy Markdown

@cegonse cegonse commented Apr 23, 2026

This PR adds a new CMake build flag, SANITIZERS_ENABLED=ON/OFF, to enable the Undefined Behavior Sanitizer (UBSAN) in tests.

UBSAN detects undefined behavior in runtime such as signed integer overflow, integer division by zero, function calls through function pointers with wrong signatures, etc (full list).

Undefined behavior can be a cause of hard to detect bugs in C code, with problems compounding when optimizations are enabled. Using UBSAN can help during development, making detecting these issues early.

Only enabled if supported by the toolchain, otherwise ignored.
Tested with Clang 14.0.6, no undefined behaviors errors were detected.
Tested working with G++ 12.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant