From ab91ec10b4a42b935183e06df3791f74869ed823 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Wed, 28 Sep 2022 23:09:19 +0200 Subject: [PATCH] Hide [[gnu::malloc(deallocator)]] in a macro MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Clang doesn't implement this attribute and reports an error. Work around it by hiding it in a macro that will be empty in clang. Reported-by: Christian Göttsche Signed-off-by: Alejandro Colomar --- lib/defines.h | 6 ++++++ lib/prototypes.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/defines.h b/lib/defines.h index d01f691e..7950cdfa 100644 --- a/lib/defines.h +++ b/lib/defines.h @@ -330,6 +330,12 @@ extern char *strerror (); /* Maximum length of passwd entry */ #define PASSWD_ENTRY_MAX_LENGTH 32768 +#if (__GNUC__ >= 11) && !defined(__clang__) +# define ATTR_MALLOC(deallocator) [[gnu::malloc(deallocator)]] +#else +# define ATTR_MALLOC(deallocator) +#endif + #ifdef HAVE_SECURE_GETENV # define shadow_getenv(name) secure_getenv(name) # else diff --git a/lib/prototypes.h b/lib/prototypes.h index 4c293aff..885c7391 100644 --- a/lib/prototypes.h +++ b/lib/prototypes.h @@ -47,7 +47,7 @@ extern int expire (const struct passwd *, /*@null@*/const struct spwd *); /* agetpass.c */ extern void erase_pass(char *pass); -[[gnu::malloc(erase_pass)]] +ATTR_MALLOC(erase_pass) extern char *agetpass(const char *prompt); /* isexpired.c */