From 17be7ea72e2dd114d9f14d9d0f458ca1412efc57 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 10 Jun 2021 10:24:58 +0200 Subject: [PATCH] glib-aux: mark result of nm_g_slice_free_fcn() as warn_unused_result It's tempting to mix up nm_g_slice_free(arg) with nm_g_slice_free_fcn(arg) Use __attribute((__warn_unused_result__)) to catch such bugs. --- src/libnm-glib-aux/nm-shared-utils.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h index 6002a0e530..b19bce9c36 100644 --- a/src/libnm-glib-aux/nm-shared-utils.h +++ b/src/libnm-glib-aux/nm-shared-utils.h @@ -1092,8 +1092,14 @@ _nm_g_slice_free_fcn_define(12); _nm_g_slice_free_fcn_define(16); _nm_g_slice_free_fcn_define(32); +_nm_warn_unused_result static inline GDestroyNotify +_nm_get_warn_unused_result_gdestroynotify(GDestroyNotify f) +{ + return f; +} + #define nm_g_slice_free_fcn1(mem_size) \ - ({ \ + _nm_get_warn_unused_result_gdestroynotify(({ \ void (*_fcn)(gpointer); \ \ /* If mem_size is a compile time constant, the compiler @@ -1132,8 +1138,9 @@ _nm_g_slice_free_fcn_define(32); _fcn = NULL; \ break; \ } \ + \ _fcn; \ - }) + })) /** * nm_g_slice_free_fcn: