From 57d05b75d34d972aa55762dc3ebda6f080e8afe1 Mon Sep 17 00:00:00 2001 From: Olivier Blin Date: Tue, 24 Sep 2024 16:33:50 +0200 Subject: [PATCH] gstrfuncs: Make _G_STR_NONNULL workaround compatible with g++ < 5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With glib >= 2.75.0 and g++ 4.8, g_str_has_prefix() from triggers -Waddress with a static const char[] argument: warning: the address of ‘xxx’ will always evaluate as ‘true’ [-Waddress] #define _G_STR_NONNULL(x) ((x) + !(x)) Check (x == NULL) instead of (!x), which still avoids -Wnonnull (gcc <= 10), but does not introduce -Waddress (g++ < 5). Co-Authored-By: Loïc Yhuel Fixes: 48730d2b3047 ("gstrfuncs: Add back x + !x warning workaround") --- glib/gstrfuncs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glib/gstrfuncs.h b/glib/gstrfuncs.h index 838ceb9fe8..7848a41b66 100644 --- a/glib/gstrfuncs.h +++ b/glib/gstrfuncs.h @@ -154,7 +154,7 @@ gboolean (g_str_has_prefix) (const gchar *str, * Without it, it thinks strlen and memcmp may be getting passed NULL * despite the explicit check for NULL right above the calls. */ -#define _G_STR_NONNULL(x) ((x) + !(x)) +#define _G_STR_NONNULL(x) ((x) + (x == NULL)) #define g_str_has_prefix(STR, PREFIX) \ (__builtin_constant_p (PREFIX)? \ -- GitLab