diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2017-02-24 15:21:39 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2017-02-24 15:21:39 -0500 |
commit | 41c16edcf6c90d1f42810ea523b7e65c99edad50 (patch) | |
tree | d13c1bd3cf1a8d853a19417bf0a3cfb8dbf8488c | |
parent | 5dbdb2f799232cb1b6df7d7a85d59ade3234d30c (diff) | |
download | postgresql-41c16edcf6c90d1f42810ea523b7e65c99edad50.tar.gz postgresql-41c16edcf6c90d1f42810ea523b7e65c99edad50.zip |
Fix unportable definition of BSWAP64() macro.
We have a portable way of writing uint64 constants, but whoever wrote
this macro didn't know about it.
While at it, fix unsafe under-parenthesization of arguments. That might
be moot, because there are already good reasons not to use the macro on
anything more complicated than a simple variable, but it's still poor
practice.
Per buildfarm warnings.
-rw-r--r-- | src/include/port/pg_bswap.h | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/include/port/pg_bswap.h b/src/include/port/pg_bswap.h index c5dcf775686..18859a6ea35 100644 --- a/src/include/port/pg_bswap.h +++ b/src/include/port/pg_bswap.h @@ -6,6 +6,7 @@ * Macros for reversing the byte order of 32-bit and 64-bit unsigned integers. * For example, 0xAABBCCDD becomes 0xDDCCBBAA. These are just wrappers for * built-in functions provided by the compiler where support exists. + * Elsewhere, beware of multiple evaluations of the arguments! * * Note that the GCC built-in functions __builtin_bswap32() and * __builtin_bswap64() are documented as accepting single arguments of type @@ -24,23 +25,23 @@ #ifdef HAVE__BUILTIN_BSWAP32 #define BSWAP32(x) __builtin_bswap32(x) #else -#define BSWAP32(x) (((x << 24) & 0xff000000) | \ - ((x << 8) & 0x00ff0000) | \ - ((x >> 8) & 0x0000ff00) | \ - ((x >> 24) & 0x000000ff)) +#define BSWAP32(x) ((((x) << 24) & 0xff000000) | \ + (((x) << 8) & 0x00ff0000) | \ + (((x) >> 8) & 0x0000ff00) | \ + (((x) >> 24) & 0x000000ff)) #endif /* HAVE__BUILTIN_BSWAP32 */ #ifdef HAVE__BUILTIN_BSWAP64 #define BSWAP64(x) __builtin_bswap64(x) #else -#define BSWAP64(x) (((x << 56) & 0xff00000000000000UL) | \ - ((x << 40) & 0x00ff000000000000UL) | \ - ((x << 24) & 0x0000ff0000000000UL) | \ - ((x << 8) & 0x000000ff00000000UL) | \ - ((x >> 8) & 0x00000000ff000000UL) | \ - ((x >> 24) & 0x0000000000ff0000UL) | \ - ((x >> 40) & 0x000000000000ff00UL) | \ - ((x >> 56) & 0x00000000000000ffUL)) +#define BSWAP64(x) ((((x) << 56) & UINT64CONST(0xff00000000000000)) | \ + (((x) << 40) & UINT64CONST(0x00ff000000000000)) | \ + (((x) << 24) & UINT64CONST(0x0000ff0000000000)) | \ + (((x) << 8) & UINT64CONST(0x000000ff00000000)) | \ + (((x) >> 8) & UINT64CONST(0x00000000ff000000)) | \ + (((x) >> 24) & UINT64CONST(0x0000000000ff0000)) | \ + (((x) >> 40) & UINT64CONST(0x000000000000ff00)) | \ + (((x) >> 56) & UINT64CONST(0x00000000000000ff))) #endif /* HAVE__BUILTIN_BSWAP64 */ /* |