From daedc3ea6d044dde18cc0c630085a7f55e764794 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 19 Dec 2017 13:54:05 -0500 Subject: [PATCH v6 1/2] Add static assertions about size of GinTernaryValue vs bool We need these to be the same because some code casts between pointers to them. --- src/backend/utils/adt/tsginidx.c | 4 +++- src/include/access/gin.h | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/backend/utils/adt/tsginidx.c b/src/backend/utils/adt/tsginidx.c index de59e6417e..00e32b2570 100644 --- a/src/backend/utils/adt/tsginidx.c +++ b/src/backend/utils/adt/tsginidx.c @@ -309,7 +309,9 @@ gin_tsquery_consistent(PG_FUNCTION_ARGS) * query. */ gcv.first_item = GETQUERY(query); - gcv.check = check; + StaticAssertStmt(sizeof(GinTernaryValue) == sizeof(bool), + "sizes of GinTernaryValue and bool are not equal"); + gcv.check = (GinTernaryValue *) check; gcv.map_item_operand = (int *) (extra_data[0]); gcv.need_recheck = recheck; diff --git a/src/include/access/gin.h b/src/include/access/gin.h index 0acdb88241..3d8a130b69 100644 --- a/src/include/access/gin.h +++ b/src/include/access/gin.h @@ -51,8 +51,8 @@ typedef struct GinStatsData /* * A ternary value used by tri-consistent functions. * - * For convenience, this is compatible with booleans. A boolean can be - * safely cast to a GinTernaryValue. + * This must be of the same size as a bool because some code will cast a + * pointer to a bool to a pointer to a GinTernaryValue. */ typedef char GinTernaryValue; base-commit: 17bb62501787c56e0518e61db13a523d47afd724 -- 2.16.2