]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
inotify-util: fix wrong warnings in FOREACH_INOTIFY_EVENT()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 25 Mar 2022 06:34:29 +0000 (15:34 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 29 Mar 2022 04:20:16 +0000 (13:20 +0900)
Follow-up for 00adc340bb15bc9d634db6caa48f1c964b99f79a.

This fixes the wrong "Received invalid inotify event, ignoring." warnings
caused by the missing curly brackets and the priorities of `&&` and `?:`.

This also replaces the ternary operators with `||`.

src/basic/inotify-util.h

index eaf1922bab65c2bda3fe1cb8718d782453414c7e..61951ff3e3244f0a1b460497e6e0c063034c1dae 100644 (file)
 
 #define _FOREACH_INOTIFY_EVENT(e, buffer, sz, log_level, start, end)    \
         for (struct inotify_event                                       \
-                            *start = &((buffer).ev),                    \
+                     *start = &((buffer).ev),                           \
                      *end = (struct inotify_event*) ((uint8_t*) start + (sz)), \
                      *e = start;                                        \
-             (uint8_t*) e + sizeof(struct inotify_event) <= (uint8_t*) end && \
-             (uint8_t*) e + sizeof(struct inotify_event) + e->len <= (uint8_t*) end ? true : \
-                     ({                                                 \
-                             log_full(log_level, "Received invalid inotify event, ignoring."); \
-                             false;                                     \
-                     });                                                \
+             (size_t) ((uint8_t*) end - (uint8_t*) e) >= sizeof(struct inotify_event) && \
+             ((size_t) ((uint8_t*) end - (uint8_t*) e) >= sizeof(struct inotify_event) + e->len || \
+              (log_full(log_level, "Received invalid inotify event, ignoring."), false)); \
              e = (struct inotify_event*) ((uint8_t*) e + sizeof(struct inotify_event) + e->len))
 
 #define _FOREACH_INOTIFY_EVENT_FULL(e, buffer, sz, log_level)           \