[PATCH 2/2] secmem: use nested #if for __has_feature test
Jussi Kivilinna
jussi.kivilinna at iki.fi
Thu Jul 23 13:32:04 CEST 2026
* src/secmem.c (lock_pool_pages): Test __has_feature with a nested #if
instead of a single combined expression.
--
GCC documents nested #if as portable form for the __has_* operators,
and flags combined defined(X) && X(...) as valid only where operator is
supported. GCC and clang both provide __has_feature, so nothing is
broken in practice, but use documented form. Select no-mlock path
through a macro so nested test keeps its else branch.
Signed-off-by: Jussi Kivilinna <jussi.kivilinna at iki.fi>
---
src/secmem.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/secmem.c b/src/secmem.c
index 7c5cac76..67fef0e6 100644
--- a/src/secmem.c
+++ b/src/secmem.c
@@ -296,7 +296,12 @@ lock_pool_pages (void *p, size_t n)
uid = getuid ();
#ifdef HAVE_BROKEN_MLOCK
-#if defined(__has_feature) && __has_feature(address_sanitizer)
+#if defined __has_feature
+# if __has_feature (address_sanitizer)
+# define GCRY_ASAN_NO_MLOCK 1
+# endif
+#endif
+#ifdef GCRY_ASAN_NO_MLOCK
/* Address sanitizer and mlock is incompatible. We can't use mlock
* with address sanitizer enabled. Proceed with NO_MLOCK=1. */
(void)p;
--
2.53.0
More information about the Gcrypt-devel
mailing list