aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-02-21 16:38:48 +0100
committerThomas Vanbesien <tvanbesi@proton.me>2026-02-21 16:38:48 +0100
commit9bb8e5cd549eca189ce183f40f771c2a614ea8f6 (patch)
tree8f21166e4e4e9fe8a4969f802e84750b026066d5 /tests
parenta8f7e6e83bc4846c94c0489e0f6e0f807b35073e (diff)
downloadLibft-9bb8e5cd549eca189ce183f40f771c2a614ea8f6.tar.gz
Libft-9bb8e5cd549eca189ce183f40f771c2a614ea8f6.zip
Add make sanitize target for AddressSanitizer leak checks
Add EXTRA variable to both Makefiles for passing extra compiler flags. Update _s_crashes() to detect ASan-intercepted crashes (non-zero exit) and suppress ASan noise from intentional NULL dereference tests.
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile2
-rw-r--r--tests/inc/test_utils.h12
2 files changed, 11 insertions, 3 deletions
diff --git a/tests/Makefile b/tests/Makefile
index 61b7d44..3fc0322 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,5 +1,5 @@
CC = cc
-CFLAGS = -I ../inc -I inc
+CFLAGS = -I ../inc -I inc $(EXTRA)
SRCDIR = src
BINDIR = bin
diff --git a/tests/inc/test_utils.h b/tests/inc/test_utils.h
index 0cb6655..56dbb94 100644
--- a/tests/inc/test_utils.h
+++ b/tests/inc/test_utils.h
@@ -115,21 +115,29 @@ _s_check_eq_int (const char *label, int got, int expected)
/* ── crash detection ──────────────────────────────────────────────── */
-/** Run @p fn in a child process; return 1 if it was killed by a signal. */
+/**
+ * Run @p fn in a child process; return 1 if it crashed.
+ * Detects both raw signals (SEGV, BUS) and ASan-intercepted crashes
+ * (which exit with non-zero instead of being killed by a signal).
+ */
static int
_s_crashes (void (*fn) (void))
{
pid_t pid;
int status;
+ fflush (stdout);
pid = fork ();
if (pid == 0)
{
+ /* Suppress ASan crash reports from intentional NULL dereferences. */
+ close (STDERR_FILENO);
fn ();
_exit (0);
}
waitpid (pid, &status, 0);
- return (WIFSIGNALED (status));
+ return (WIFSIGNALED (status)
+ || (WIFEXITED (status) && WEXITSTATUS (status) != 0));
}
static void