Skip to content

Commit fce4609

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/[email protected]
1 parent b21e665 commit fce4609

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/include/access/htup_details.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ struct HeapTupleHeaderData
237237
*/
238238
#define HEAP_LOCKED_UPGRADED(infomask) \
239239
( \
240-
((infomask) & HEAP_XMAX_IS_MULTI) && \
241-
((infomask) & HEAP_XMAX_LOCK_ONLY) && \
240+
((infomask) & HEAP_XMAX_IS_MULTI) != 0 && \
241+
((infomask) & HEAP_XMAX_LOCK_ONLY) != 0 && \
242242
(((infomask) & (HEAP_XMAX_EXCL_LOCK | HEAP_XMAX_KEYSHR_LOCK)) == 0) \
243243
)
244244

@@ -317,7 +317,7 @@ struct HeapTupleHeaderData
317317

318318
#define HeapTupleHeaderXminCommitted(tup) \
319319
( \
320-
(tup)->t_infomask & HEAP_XMIN_COMMITTED \
320+
((tup)->t_infomask & HEAP_XMIN_COMMITTED) != 0 \
321321
)
322322

323323
#define HeapTupleHeaderXminInvalid(tup) \
@@ -501,7 +501,7 @@ do { \
501501

502502
#define HeapTupleHeaderIsHeapOnly(tup) \
503503
( \
504-
(tup)->t_infomask2 & HEAP_ONLY_TUPLE \
504+
((tup)->t_infomask2 & HEAP_ONLY_TUPLE) != 0 \
505505
)
506506

507507
#define HeapTupleHeaderSetHeapOnly(tup) \
@@ -516,7 +516,7 @@ do { \
516516

517517
#define HeapTupleHeaderHasMatch(tup) \
518518
( \
519-
(tup)->t_infomask2 & HEAP_TUPLE_HAS_MATCH \
519+
((tup)->t_infomask2 & HEAP_TUPLE_HAS_MATCH) != 0 \
520520
)
521521

522522
#define HeapTupleHeaderSetMatch(tup) \

0 commit comments

Comments
 (0)