From 81669507632e530e4c60b745f209a73fda2ddc21 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 25 Mar 2022 15:34:29 +0900 Subject: [PATCH] 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 `||`. --- src/basic/inotify-util.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/basic/inotify-util.h b/src/basic/inotify-util.h index eaf1922bab..61951ff3e3 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) \