diff --git a/.github/workflows/build-check.yaml b/.github/workflows/build-check.yaml index be3e52d7e..9b925935d 100644 --- a/.github/workflows/build-check.yaml +++ b/.github/workflows/build-check.yaml @@ -30,6 +30,7 @@ jobs: - name: Build & run tests run: | sudo apt install -y ninja-build + cmake -DASAN=ON -B build/ -G Ninja CMAKE_GENERATOR=Ninja make test check_format: @@ -290,6 +291,7 @@ jobs: - name: Build & test pico run: | sudo apt install -y ninja-build + cmake -DASAN=ON -B build/ -G Ninja CMAKE_GENERATOR=Ninja make python3 ./build/tests/no_router.py timeout-minutes: 5 diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ef984042..315e08921 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,8 +96,7 @@ else() if (NOT CMAKE_C_STANDARD STREQUAL "99") add_compile_options(-Wpedantic) endif() - # add_compile_options(-Wconversion) - # add_link_options(-fsanitize=address) + add_compile_options(-Wconversion) elseif(MSVC) add_compile_options(/W4 /WX /Od /wd4127) elseif(CMAKE_SYSTEM_NAME MATCHES "Generic") @@ -379,12 +378,14 @@ option(BUILD_EXAMPLES "Use this to also build the examples." ON) option(BUILD_TOOLS "Use this to also build the tools." OFF) option(BUILD_TESTING "Use this to also build tests." ON) option(BUILD_INTEGRATION "Use this to also build integration tests." OFF) +option(ASAN "Enable AddressSanitizer." OFF) message(STATUS "Produce Debian and RPM packages: ${PACKAGING}") message(STATUS "Build examples: ${BUILD_EXAMPLES}") message(STATUS "Build tools: ${BUILD_TOOLS}") message(STATUS "Build tests: ${BUILD_TESTING}") message(STATUS "Build integration: ${BUILD_INTEGRATION}") +message(STATUS "AddressSanitizer: ${ASAN}") set(PICO_LIBS "") if(PICO_STATIC) @@ -453,6 +454,11 @@ if(BUILD_EXAMPLES) add_subdirectory(examples) endif() +if(ASAN) + add_compile_options(-fsanitize=address) + add_link_options(-fsanitize=address) +endif() + if(UNIX OR MSVC) if(BUILD_TOOLS) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tools) diff --git a/GNUmakefile b/GNUmakefile index 0a254575c..7f12f9b91 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -82,7 +82,7 @@ CMAKE_OPT=-DZENOH_DEBUG=$(ZENOH_DEBUG) -DBUILD_EXAMPLES=$(BUILD_EXAMPLES) -DCMAK -DZ_FEATURE_MULTI_THREAD=$(Z_FEATURE_MULTI_THREAD) -DZ_FEATURE_INTEREST=$(Z_FEATURE_INTEREST) -DZ_FEATURE_UNSTABLE_API=$(Z_FEATURE_UNSTABLE_API)\ -DZ_FEATURE_PUBLICATION=$(Z_FEATURE_PUBLICATION) -DZ_FEATURE_SUBSCRIPTION=$(Z_FEATURE_SUBSCRIPTION) -DZ_FEATURE_QUERY=$(Z_FEATURE_QUERY) -DZ_FEATURE_QUERYABLE=$(Z_FEATURE_QUERYABLE)\ -DZ_FEATURE_RAWETH_TRANSPORT=$(Z_FEATURE_RAWETH_TRANSPORT) -DFRAG_MAX_SIZE=$(FRAG_MAX_SIZE) -DBATCH_UNICAST_SIZE=$(BATCH_UNICAST_SIZE) -DBATCH_MULTICAST_SIZE=$(BATCH_MULTICAST_SIZE)\ - -DBUILD_INTEGRATION=$(BUILD_INTEGRATION) -DBUILD_TOOLS=$(BUILD_TOOLS) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -H. + -DASAN=$(ASAN) -DBUILD_INTEGRATION=$(BUILD_INTEGRATION) -DBUILD_TOOLS=$(BUILD_TOOLS) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -H. ifeq ($(FORCE_C99), ON) CMAKE_OPT += -DCMAKE_C_STANDARD=99