Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit41c16ed

Browse files
committed
Fix unportable definition of BSWAP64() macro.
We have a portable way of writing uint64 constants, but whoever wrotethis macro didn't know about it.While at it, fix unsafe under-parenthesization of arguments. That mightbe moot, because there are already good reasons not to use the macro onanything more complicated than a simple variable, but it's still poorpractice.Per buildfarm warnings.
1 parent5dbdb2f commit41c16ed

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

‎src/include/port/pg_bswap.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Macros for reversing the byte order of 32-bit and 64-bit unsigned integers.
77
* For example, 0xAABBCCDD becomes 0xDDCCBBAA. These are just wrappers for
88
* built-in functions provided by the compiler where support exists.
9+
* Elsewhere, beware of multiple evaluations of the arguments!
910
*
1011
* Note that the GCC built-in functions __builtin_bswap32() and
1112
* __builtin_bswap64() are documented as accepting single arguments of type
@@ -24,23 +25,23 @@
2425
#ifdefHAVE__BUILTIN_BSWAP32
2526
#defineBSWAP32(x) __builtin_bswap32(x)
2627
#else
27-
#defineBSWAP32(x) (((x << 24) & 0xff000000) | \
28-
((x << 8) & 0x00ff0000) | \
29-
((x >> 8) & 0x0000ff00) | \
30-
((x >> 24) & 0x000000ff))
28+
#defineBSWAP32(x) ((((x) << 24) & 0xff000000) | \
29+
(((x) << 8) & 0x00ff0000) | \
30+
(((x) >> 8) & 0x0000ff00) | \
31+
(((x) >> 24) & 0x000000ff))
3132
#endif/* HAVE__BUILTIN_BSWAP32 */
3233

3334
#ifdefHAVE__BUILTIN_BSWAP64
3435
#defineBSWAP64(x) __builtin_bswap64(x)
3536
#else
36-
#defineBSWAP64(x) (((x << 56) &0xff00000000000000UL) | \
37-
((x << 40) &0x00ff000000000000UL) | \
38-
((x << 24) &0x0000ff0000000000UL) | \
39-
((x << 8)& 0x000000ff00000000UL) | \
40-
((x >> 8)& 0x00000000ff000000UL) | \
41-
((x >> 24) &0x0000000000ff0000UL) | \
42-
((x >> 40) &0x000000000000ff00UL) | \
43-
((x >> 56) &0x00000000000000ffUL))
37+
#defineBSWAP64(x) ((((x) << 56) &UINT64CONST(0xff00000000000000)) | \
38+
(((x) << 40) &UINT64CONST(0x00ff000000000000)) | \
39+
(((x) << 24) &UINT64CONST(0x0000ff0000000000)) | \
40+
(((x) << 8) & UINT64CONST(0x000000ff00000000)) | \
41+
(((x) >> 8) & UINT64CONST(0x00000000ff000000)) | \
42+
(((x) >> 24) &UINT64CONST(0x0000000000ff0000)) | \
43+
(((x) >> 40) &UINT64CONST(0x000000000000ff00)) | \
44+
(((x) >> 56) &UINT64CONST(0x00000000000000ff)))
4445
#endif/* HAVE__BUILTIN_BSWAP64 */
4546

4647
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp