From: Yu Watanabe Date: Fri, 25 Mar 2022 06:34:29 +0000 (+0900) Subject: inotify-util: fix wrong warnings in FOREACH_INOTIFY_EVENT() X-Git-Tag: v251-rc1~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=81669507632e530e4c60b745f209a73fda2ddc21;p=thirdparty%2Fsystemd.git inotify-util: fix wrong warnings in FOREACH_INOTIFY_EVENT() 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 `||`. --- diff --git a/src/basic/inotify-util.h b/src/basic/inotify-util.h index eaf1922bab6..61951ff3e32 100644 --- a/src/basic/inotify-util.h +++ b/src/basic/inotify-util.h @@ -12,15 +12,12 @@ #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) \