utils: make le16 endian conversion functions work with arguments that have side effects
authorFelix Fietkau <nbd@openwrt.org>
Thu, 14 Feb 2013 22:39:57 +0000 (23:39 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Thu, 14 Feb 2013 22:39:57 +0000 (23:39 +0100)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
utils.h

diff --git a/utils.h b/utils.h
index 41ea02cc95b6f07acc07fe50449714590e1a9b74..71a469225d5fbdff8694e4684f9d541d87ab0e8a 100644 (file)
--- a/utils.h
+++ b/utils.h
@@ -99,7 +99,7 @@ void clock_gettime(int type, struct timespec *tv);
 #define __LITTLE_ENDIAN LITTLE_ENDIAN
 #endif
 
-#define __u_bswap16(x) ((uint16_t)((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8)))
+#define __u_bswap16(x) ({ uint16_t val = (x); ((uint16_t)(((val >> 8) & 0xffu) | ((val & 0xffu) << 8))); })
 
 #if _GNUC_MIN_VER(4, 2)
 #define __u_bswap32(x) __builtin_bswap32(x)