From d580ea90c3ec9fabab9930d7d179c94048a7ae70 Mon Sep 17 00:00:00 2001 From: dim Date: Fri, 23 Mar 2012 10:55:19 +0000 Subject: [PATCH] MFC r232745: Add casts to __uint16_t to the __bswap16() macros on all arches which didn't already have them. This is because the ternary expression will return int, due to the Usual Arithmetic Conversions. Such casts are not needed for the 32 and 64 bit variants. While here, add additional parentheses around the x86 variant, to protect against unintended consequences. git-svn-id: svn://svn.freebsd.org/base/stable/9@233349 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sys/amd64/include/endian.h | 4 ++-- sys/i386/include/endian.h | 4 ++-- sys/powerpc/include/endian.h | 4 ++-- sys/sparc64/include/endian.h | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sys/amd64/include/endian.h b/sys/amd64/include/endian.h index de22c8bdd..c34677282 100644 --- a/sys/amd64/include/endian.h +++ b/sys/amd64/include/endian.h @@ -119,8 +119,8 @@ __bswap16_var(__uint16_t _x) __bswap32_const((__uint32_t)(_x)) : __bswap32_var(_x)) #define __bswap16(_x) \ - (__builtin_constant_p(_x) ? \ - __bswap16_const((__uint16_t)(_x)) : __bswap16_var(_x)) + ((__uint16_t)(__builtin_constant_p(_x) ? \ + __bswap16_const((__uint16_t)(_x)) : __bswap16_var(_x))) #define __htonl(x) __bswap32(x) #define __htons(x) __bswap16(x) diff --git a/sys/i386/include/endian.h b/sys/i386/include/endian.h index c09dfb164..35f6f57a1 100644 --- a/sys/i386/include/endian.h +++ b/sys/i386/include/endian.h @@ -119,8 +119,8 @@ __bswap16_var(__uint16_t _x) __bswap32_const((__uint32_t)(_x)) : __bswap32_var(_x)) #define __bswap16(_x) \ - (__builtin_constant_p(_x) ? \ - __bswap16_const((__uint16_t)(_x)) : __bswap16_var(_x)) + ((__uint16_t)(__builtin_constant_p(_x) ? \ + __bswap16_const((__uint16_t)(_x)) : __bswap16_var(_x))) #define __htonl(x) __bswap32(x) #define __htons(x) __bswap16(x) diff --git a/sys/powerpc/include/endian.h b/sys/powerpc/include/endian.h index 15dd7db31..bfca169f5 100644 --- a/sys/powerpc/include/endian.h +++ b/sys/powerpc/include/endian.h @@ -124,8 +124,8 @@ __bswap64_var(__uint64_t _x) ((_x << 40) & ((__uint64_t)0xff << 48)) | ((_x << 56))); } -#define __bswap16(x) (__is_constant(x) ? __bswap16_const(x) : \ - __bswap16_var(x)) +#define __bswap16(x) ((__uint16_t)(__is_constant(x) ? __bswap16_const(x) : \ + __bswap16_var(x))) #define __bswap32(x) (__is_constant(x) ? __bswap32_const(x) : \ __bswap32_var(x)) #define __bswap64(x) (__is_constant(x) ? __bswap64_const(x) : \ diff --git a/sys/sparc64/include/endian.h b/sys/sparc64/include/endian.h index 2ca467e40..38e7c3030 100644 --- a/sys/sparc64/include/endian.h +++ b/sys/sparc64/include/endian.h @@ -109,8 +109,8 @@ __bswap64_var(__uint64_t _x) ((_x << 40) & ((__uint64_t)0xff << 48)) | ((_x << 56))); } -#define __bswap16(x) (__is_constant(x) ? __bswap16_const(x) : \ - __bswap16_var(x)) +#define __bswap16(x) ((__uint16_t)(__is_constant(x) ? __bswap16_const(x) : \ + __bswap16_var(x))) #define __bswap32(x) (__is_constant(x) ? __bswap32_const(x) : \ __bswap32_var(x)) #define __bswap64(x) (__is_constant(x) ? __bswap64_const(x) : \ -- 2.45.0