Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 39055cb

Browse files
committed
Bring some MSVC asserts in line with other platforms
MSVC's _BitScan* functions return a boolean indicating whether any bits were set in the input, and we were previously asserting that they returned true, per our API. This is correct. However, other platforms simply assert that the input is non-zero, so do that to be more consistent. Noted while investigating a hypothesis from Ranier Vilela about undefined behavior, but this is not his proposed patch. Discussion: https://www.postgresql.org/message-id/CAEudQAoDhUZyKGJ1vbMGcgVUOcsixe-%3DjcVaDWarqkUg163D2w%40mail.gmail.com
1 parent 7395a90 commit 39055cb

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/include/port/pg_bitutils.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ pg_leftmost_one_pos32(uint32 word)
4848
unsigned long result;
4949
bool non_zero;
5050

51+
Assert(word != 0);
52+
5153
non_zero = _BitScanReverse(&result, word);
52-
Assert(non_zero);
5354
return (int) result;
5455
#else
5556
int shift = 32 - 8;
@@ -85,8 +86,9 @@ pg_leftmost_one_pos64(uint64 word)
8586
unsigned long result;
8687
bool non_zero;
8788

89+
Assert(word != 0);
90+
8891
non_zero = _BitScanReverse64(&result, word);
89-
Assert(non_zero);
9092
return (int) result;
9193
#else
9294
int shift = 64 - 8;
@@ -116,8 +118,9 @@ pg_rightmost_one_pos32(uint32 word)
116118
unsigned long result;
117119
bool non_zero;
118120

121+
Assert(word != 0);
122+
119123
non_zero = _BitScanForward(&result, word);
120-
Assert(non_zero);
121124
return (int) result;
122125
#else
123126
int result = 0;
@@ -156,8 +159,9 @@ pg_rightmost_one_pos64(uint64 word)
156159
unsigned long result;
157160
bool non_zero;
158161

162+
Assert(word != 0);
163+
159164
non_zero = _BitScanForward64(&result, word);
160-
Assert(non_zero);
161165
return (int) result;
162166
#else
163167
int result = 0;

0 commit comments

Comments
 (0)