Swap conditions for ARRAY_FOR_EACH()
authorPeter Hutterer <peter.hutterer@who-t.net>
Fri, 22 Aug 2014 05:08:57 +0000 (15:08 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Tue, 26 Aug 2014 01:04:42 +0000 (11:04 +1000)
The current conditions result in _elem being assigned _arr[i] before the
condition is checked. This is fine since we then break from the loop and don't
access it anyway, but it makes Coverity unhappy.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
src/libinput-util.h

index 2f1a1db..5d366b0 100644 (file)
@@ -76,7 +76,7 @@ int list_empty(const struct list *list);
 #define NLONGS(x) (((x) + LONG_BITS - 1) / LONG_BITS)
 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
 #define ARRAY_FOR_EACH(_arr, _elem) \
-       for (size_t _i = 0; (_elem = &_arr[_i]) && _i < ARRAY_LENGTH(_arr); _i++)
+       for (size_t _i = 0; _i < ARRAY_LENGTH(_arr) && (_elem = &_arr[_i]); _i++)
 
 #define min(a, b) (((a) < (b)) ? (a) : (b))
 #define max(a, b) (((a) > (b)) ? (a) : (b))