From c9b5eb5024fcfc48bee93d621778dcacba8dd575 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Fri, 15 Dec 2017 17:01:03 -0500 Subject: [PATCH v4 1/3] Add static assertions about size of GinNullCategory vs bool We need these to be the same because some code uses an array of one as the other. If bool were a different size (e.g., because stdbool.h is used, which could make sizeof(bool) == 4 in some configurations), then this would silently break. Since GinNullCategory is signed char and bool is a char of unspecified signedness, there need to be explicit casts between the two, otherwise the compiler would complain. But those casts also silently hide any size mismatches. --- src/backend/access/gin/ginscan.c | 6 +++++- src/backend/access/gin/ginutil.c | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/backend/access/gin/ginscan.c b/src/backend/access/gin/ginscan.c index 7ceea7a741..eaf4ae6fdf 100644 --- a/src/backend/access/gin/ginscan.c +++ b/src/backend/access/gin/ginscan.c @@ -367,8 +367,12 @@ ginNewScanKey(IndexScanDesc scan) } } } - /* now we can use the nullFlags as category codes */ + /* + * now we can use the nullFlags as category codes + */ + StaticAssertStmt(sizeof(GinNullCategory) == sizeof(bool), + "sizes of GinNullCategory and bool are not equal"); ginFillScanKey(so, skey->sk_attno, skey->sk_strategy, searchMode, skey->sk_argument, nQueryValues, diff --git a/src/backend/access/gin/ginutil.c b/src/backend/access/gin/ginutil.c index d9c6483437..28912e416a 100644 --- a/src/backend/access/gin/ginutil.c +++ b/src/backend/access/gin/ginutil.c @@ -540,7 +540,12 @@ ginExtractEntries(GinState *ginstate, OffsetNumber attnum, for (i = 0; i < *nentries; i++) nullFlags[i] = (nullFlags[i] ? true : false); } - /* now we can use the nullFlags as category codes */ + + /* + * now we can use the nullFlags as category codes + */ + StaticAssertStmt(sizeof(GinNullCategory) == sizeof(bool), + "sizes of GinNullCategory and bool are not equal"); *categories = (GinNullCategory *) nullFlags; /* base-commit: 7d3583ad9ae54b44119973a9d6d731c9cc74c86e -- 2.15.1