Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 23 Mar 2012 10:55:19 +0000 (UTC)
From:      Dimitry Andric <dim@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r233349 - in stable/9/sys: amd64/include i386/include powerpc/include sparc64/include
Message-ID:  <201203231055.q2NAtJ9p070979@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dim
Date: Fri Mar 23 10:55:19 2012
New Revision: 233349
URL: http://svn.freebsd.org/changeset/base/233349

Log:
  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.

Modified:
  stable/9/sys/amd64/include/endian.h
  stable/9/sys/i386/include/endian.h
  stable/9/sys/powerpc/include/endian.h
  stable/9/sys/sparc64/include/endian.h
Directory Properties:
  stable/9/sys/   (props changed)

Modified: stable/9/sys/amd64/include/endian.h
==============================================================================
--- stable/9/sys/amd64/include/endian.h	Fri Mar 23 10:39:50 2012	(r233348)
+++ stable/9/sys/amd64/include/endian.h	Fri Mar 23 10:55:19 2012	(r233349)
@@ -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)

Modified: stable/9/sys/i386/include/endian.h
==============================================================================
--- stable/9/sys/i386/include/endian.h	Fri Mar 23 10:39:50 2012	(r233348)
+++ stable/9/sys/i386/include/endian.h	Fri Mar 23 10:55:19 2012	(r233349)
@@ -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)

Modified: stable/9/sys/powerpc/include/endian.h
==============================================================================
--- stable/9/sys/powerpc/include/endian.h	Fri Mar 23 10:39:50 2012	(r233348)
+++ stable/9/sys/powerpc/include/endian.h	Fri Mar 23 10:55:19 2012	(r233349)
@@ -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) : \

Modified: stable/9/sys/sparc64/include/endian.h
==============================================================================
--- stable/9/sys/sparc64/include/endian.h	Fri Mar 23 10:39:50 2012	(r233348)
+++ stable/9/sys/sparc64/include/endian.h	Fri Mar 23 10:55:19 2012	(r233349)
@@ -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) : \



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201203231055.q2NAtJ9p070979>