8000 Change some test macros to return true booleans · hackingwu/postgres@e0f4a80 · GitHub
[go: up one dir, main page]

Skip to content

Commit e0f4a80

Browse files
committed
Change some test macros to return true booleans
These macros work fine when they are used directly in an "if" test or similar, but as soon as the return values are assigned to boolean variables (or passed as boolean arguments to some function), they become bugs, hopefully caught by compiler warnings. To avoid future problems, fix the definitions so that they return actual booleans. To further minimize the risk that somebody uses them in back-patched fixes that only work correctly in branches starting from the current master and not in old ones, back-patch the change to supported branches as appropriate. See also commit af4472b, and the long discussion (and larger patch) in the thread mentioned in its commit message. Discussion: https://postgr.es/m/18672.1483022414@sss.pgh.pa.us
1 parent f64b11f commit e0f4a80

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/include/access/htup_details.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ struct HeapTupleHeaderData
223223
*/
224224
#define HEAP_LOCKED_UPGRADED(infomask) \
225225
( \
226-
((infomask) & HEAP_XMAX_IS_MULTI) && \
227-
((infomask) & HEAP_XMAX_LOCK_ONLY) && \
226+
((infomask) & HEAP_XMAX_IS_MULTI) != 0 && \
227+
((infomask) & HEAP_XMAX_LOCK_ONLY) != 0 && \
228228
(((infomask) & (HEAP_XMAX_EXCL_LOCK | HEAP_XMAX_KEYSHR_LOCK)) == 0) \
229229
)
230230

@@ -414,7 +414,7 @@ do { \
414414

415415
#define HeapTupleHeaderIsHeapOnly(tup) \
416416
( \
417-
(tup)->t_infomask2 & HEAP_ONLY_TUPLE \
417+
((tup)->t_infomask2 & HEAP_ONLY_TUPLE) != 0 \
418418
)
419419

420420
#define HeapTupleHeaderSetHeapOnly(tup) \
@@ -429,7 +429,7 @@ do { \
429429

430430
#define HeapTupleHeaderHasMatch(tup) \
431431
( \
432-
(tup)->t_infomask2 & HEAP_TUPLE_HAS_MATCH \
432+
((tup)->t_infomask2 & HEAP_TUPLE_HAS_MATCH) != 0 \
433433
)
434434

435435
#define HeapTupleHeaderSetMatch(tup) \

0 commit comments

Comments
 (0)
0