From 5fe6b63a62dfd4c3454b17aa80a2bfb4765f8a27 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 31 Jul 2023 11:48:40 +0200 Subject: [PATCH] std-aux: add static-asserts about signedness for NM_CMP_DIRECT() --- src/libnm-std-aux/nm-std-aux.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/libnm-std-aux/nm-std-aux.h b/src/libnm-std-aux/nm-std-aux.h index 623a7c1e03..46d8f2025e 100644 --- a/src/libnm-std-aux/nm-std-aux.h +++ b/src/libnm-std-aux/nm-std-aux.h @@ -1302,13 +1302,15 @@ nm_ptr_to_uintptr(const void *p) /*****************************************************************************/ -#define NM_CMP_DIRECT(a, b) \ - do { \ - typeof(a) _a = (a); \ - typeof(b) _b = (b); \ - \ - if (_a != _b) \ - return (_a < _b) ? -1 : 1; \ +#define NM_CMP_DIRECT(a, b) \ + do { \ + typeof(a) _a = (a); \ + typeof(b) _b = (b); \ + \ + G_STATIC_ASSERT(_NM_INT_SAME_SIGNEDNESS(_a, _b)); \ + \ + if (_a != _b) \ + return (_a < _b) ? -1 : 1; \ } while (0) #define NM_CMP_DIRECT_UNSAFE(a, b) \