build: Add support for sanitizer compiler flags
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 18582ed..e701dda 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,6 +1,6 @@
.unit-tests:
script:
- - ./autogen && ./configure
+ - ./autogen && ./configure --enable-sanitize
- make check
.coverage:
diff --git a/configure.ac b/configure.ac
index 4faddd0..1b7d182 100644
--- a/configure.ac
+++ b/configure.ac
@@ -101,6 +101,18 @@ AS_IF([test "$user_CFLAGS" = unset], [
LIBBSD_CHECK_COMPILER_FLAG([-Wwrite-strings])
CFLAGS="$CFLAGS $LIBBSD_COMPILER_FLAGS"
+
+ AC_ARG_ENABLE([sanitize],
+ [AS_HELP_STRING([--enable-sanitize], [enable compiler sanitizer support])],
+ [
+ LIBBSD_COMPILER_FLAGS=''
+ LIBBSD_CHECK_COMPILER_FLAG([-fsanitize=address])
+ LIBBSD_CHECK_COMPILER_FLAG([-fsanitize=leak])
+ LIBBSD_CHECK_COMPILER_FLAG([-fsanitize=undefined])
+
+ CFLAGS="$CFLAGS $LIBBSD_COMPILER_FLAGS"
+ LDFLAGS="$LDFLAGS $LIBBSD_COMPILER_FLAGS"
+ ])
])
# Checks for libraries.