From 7f63902acd98302df37346e35444f11aa38cdd03 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Mon, 25 Dec 2023 13:23:27 -0800 Subject: [PATCH] Avoid Clang warnings in util/xmalloc.c The preprocessor code to suppress false positive GCC warnings needs to be wrapped in a conditional since Clang doesn't understand that warning flag. --- util/xmalloc.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/util/xmalloc.c b/util/xmalloc.c index 43f26a1..21b53d5 100644 --- a/util/xmalloc.c +++ b/util/xmalloc.c @@ -159,14 +159,18 @@ x_realloc(void *p, size_t size, const char *file, int line) * that if realloc fails (which is true in every case when it returns * NULL when size > 0), p is unchanged and still valid. */ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wuse-after-free" +#if !defined(__clang__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wuse-after-free" +#endif while (newp == NULL) { (*xmalloc_error_handler)("realloc", size, file, line); newp = realloc(p, size); } return newp; -#pragma GCC diagnostic pop +#if !defined(__clang__) +# pragma GCC diagnostic pop +#endif } @@ -186,13 +190,17 @@ x_reallocarray(void *p, size_t n, size_t size, const char *file, int line) * every case when it returns NULL when size > 0 and n > 0), p is * unchanged and still valid. */ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wuse-after-free" +#if !defined(__clang__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wuse-after-free" +#endif while (newp == NULL) { (*xmalloc_error_handler)("reallocarray", n *size, file, line); newp = reallocarray(p, n, size); } -#pragma GCC diagnostic pop +#if !defined(__clang__) +# pragma GCC diagnostic pop +#endif return newp; } -- 2.39.2