summaryrefslogtreecommitdiff
path: root/shared/nm-utils/nm-shared-utils.h
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-12-07 12:31:55 +0100
committerThomas Haller <thaller@redhat.com>2017-12-15 11:48:38 +0100
commit974501fdcfa91547539ad1049c0cb3339c08efb3 (patch)
treea307809a731037fc0788736d2decce7085b29a39 /shared/nm-utils/nm-shared-utils.h
parent9c3402aa1e145420b868359e993b0a38ae9a6408 (diff)
downloadNetworkManager-th/static-asserts.tar.gz
shared: add static assert for nm_g_slice_free_fcn() argumentth/static-asserts
Diffstat (limited to 'shared/nm-utils/nm-shared-utils.h')
-rw-r--r--shared/nm-utils/nm-shared-utils.h10
1 files changed, 8 insertions, 2 deletions
diff --git a/shared/nm-utils/nm-shared-utils.h b/shared/nm-utils/nm-shared-utils.h
index 89ad8b8d48..17024d591f 100644
--- a/shared/nm-utils/nm-shared-utils.h
+++ b/shared/nm-utils/nm-shared-utils.h
@@ -326,12 +326,18 @@ _nm_g_slice_free_fcn_define (16)
/* If mem_size is a compile time constant, the compiler
* will be able to optimize this. Hence, you don't want
* to call this with a non-constant size argument. */ \
- switch (mem_size) { \
+ G_STATIC_ASSERT_EXPR ( ((mem_size) == 1) \
+ || ((mem_size) == 2) \
+ || ((mem_size) == 4) \
+ || ((mem_size) == 8) \
+ || ((mem_size) == 12) \
+ || ((mem_size) == 16)); \
+ switch ((mem_size)) { \
case 1: _fcn = _nm_g_slice_free_fcn_1; break; \
case 2: _fcn = _nm_g_slice_free_fcn_2; break; \
case 4: _fcn = _nm_g_slice_free_fcn_4; break; \
case 8: _fcn = _nm_g_slice_free_fcn_8; break; \
- case 12: _fcn = _nm_g_slice_free_fcn_12; break; \
+ case 12: _fcn = _nm_g_slice_free_fcn_12; break; \
case 16: _fcn = _nm_g_slice_free_fcn_16; break; \
default: g_assert_not_reached (); _fcn = NULL; break; \
} \