]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
logind: replace handle_action_valid() macro by inline function
authorLennart Poettering <lennart@poettering.net>
Tue, 22 Feb 2022 12:05:16 +0000 (13:05 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 9 Mar 2022 15:24:10 +0000 (16:24 +0100)
The old macro will double evaluation and has no protection against
operator precedence issues. Let's fix that by using an inline func
instead, which also gives us typesafety.

src/login/logind-action.h

index 4dcf719488d0a50cb9d8c9ccedef73b8937de5e8..dc073fe951b250f36ef115a8d2b9fa47cc0b9917 100644 (file)
@@ -21,12 +21,14 @@ typedef enum HandleAction {
 
 typedef struct ActionTableItem ActionTableItem;
 
-#define handle_action_valid(x) (x >= 0 && x < _HANDLE_ACTION_MAX)
-
 #include "logind-inhibit.h"
 #include "logind.h"
 #include "sleep-config.h"
 
+static inline bool handle_action_valid(HandleAction a) {
+        return a >= 0 && a < _HANDLE_ACTION_MAX;
+}
+
 struct ActionTableItem {
         HandleAction handle;
         const char *target;