From 330bedfb47b114d69d0ca21c2802cacb295de08d Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Sun, 12 Jul 2026 13:26:25 +0100 Subject: [PATCH] Build with ASAN on macOS by default. --- Makefile.am | 3 ++- configure.ac | 2 +- grid.c | 3 +++ tmux.c | 18 ++++++++++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index d985e510d..84bdbdb2a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -43,7 +43,8 @@ AM_CPPFLAGS += -DDEBUG endif AM_CPPFLAGS += -iquote. if IS_ASAN -AM_CFLAGS += -fsanitize=address +AM_CPPFLAGS += -DASAN +AM_CFLAGS += -fsanitize=address -fno-omit-frame-pointer AM_LDFLAGS += -fsanitize=address endif endif diff --git a/configure.ac b/configure.ac index 6abb2d9d5..c118800b8 100644 --- a/configure.ac +++ b/configure.ac @@ -78,7 +78,7 @@ AC_ARG_ENABLE( asan, AS_HELP_STRING(--enable-asan, enable ASAN build flags), , - enable_asan=no + [case "x$host_os" in *darwin*) enable_asan=yes;; esac] ) AM_CONDITIONAL(IS_ASAN, test "x$enable_asan" = xyes) diff --git a/grid.c b/grid.c index d03352f08..99d5371a9 100644 --- a/grid.c +++ b/grid.c @@ -366,6 +366,9 @@ grid_create(u_int sx, u_int sy, u_int hlimit) if (gd->sy != 0) gd->linedata = xcalloc(gd->sy, sizeof *gd->linedata); +#ifdef __APPLE__ + assert(gd->hsize == 0); +#endif grid_check_is_clear(gd); return (gd); } diff --git a/tmux.c b/tmux.c index 132c39217..3739b6008 100644 --- a/tmux.c +++ b/tmux.c @@ -49,6 +49,24 @@ static char *make_label(const char *, char **); static int areshell(const char *); static const char *getshell(void); +#ifdef ASAN +__attribute__((used)) const char *__asan_default_options(void); +__attribute__((used)) const char * +__asan_default_options(void) +{ + return ( + "abort_on_error=1:" + "halt_on_error=1:" + "detect_leaks=0:" + "detect_stack_use_after_return=1:" + "strict_string_checks=1:" + "check_initialization_order=1:" + "log_path=/tmp/tmux-asan:" + "log_exe_name=1" + ); +} +#endif + static __dead void usage(int status) {