json_script: do not rely on global includes for other libubox header files
[project/libubox.git] / utils.h
diff --git a/utils.h b/utils.h
index 03cecb0..71a4692 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)
@@ -113,11 +113,11 @@ void clock_gettime(int type, struct timespec *tv);
 
 #define cpu_to_be64(x) __u_bswap64(x)
 #define cpu_to_be32(x) __u_bswap32(x)
-#define cpu_to_be16(x) __u_bswap16((uint16_t) x)
+#define cpu_to_be16(x) __u_bswap16((uint16_t) (x))
 
 #define be64_to_cpu(x) __u_bswap64(x)
 #define be32_to_cpu(x) __u_bswap32(x)
-#define be16_to_cpu(x) __u_bswap16((uint16_t) x)
+#define be16_to_cpu(x) __u_bswap16((uint16_t) (x))
 
 #define cpu_to_le64(x) (x)
 #define cpu_to_le32(x) (x)
@@ -131,11 +131,11 @@ void clock_gettime(int type, struct timespec *tv);
 
 #define cpu_to_le64(x) __u_bswap64(x)
 #define cpu_to_le32(x) __u_bswap32(x)
-#define cpu_to_le16(x) __u_bswap16((uint16_t) x)
+#define cpu_to_le16(x) __u_bswap16((uint16_t) (x))
 
 #define le64_to_cpu(x) __u_bswap64(x)
 #define le32_to_cpu(x) __u_bswap32(x)
-#define le16_to_cpu(x) __u_bswap16((uint16_t) x)
+#define le16_to_cpu(x) __u_bswap16((uint16_t) (x))
 
 #define cpu_to_be64(x) (x)
 #define cpu_to_be32(x) (x)