mirror of
https://github.com/postgres/postgres.git
synced 2025-10-25 13:17:41 +03:00
Use FLEXIBLE_ARRAY_MEMBER in a bunch more places.
Replace some bogus "x[1]" declarations with "x[FLEXIBLE_ARRAY_MEMBER]". Aside from being more self-documenting, this should help prevent bogus warnings from static code analyzers and perhaps compiler misoptimizations. This patch is just a down payment on eliminating the whole problem, but it gets rid of a lot of easy-to-fix cases. Note that the main problem with doing this is that one must no longer rely on computing sizeof(the containing struct), since the result would be compiler-dependent. Instead use offsetof(struct, lastfield). Autoconf also warns against spelling that offsetof(struct, lastfield[0]). Michael Paquier, review and additional fixes by me.
This commit is contained in:
@@ -322,7 +322,7 @@ typedef struct GinOptions
|
||||
{
|
||||
int32 vl_len_; /* varlena header (do not touch directly!) */
|
||||
bool useFastUpdate; /* use fast updates? */
|
||||
int pendingListCleanupSize; /* maximum size of pending list */
|
||||
int pendingListCleanupSize; /* maximum size of pending list */
|
||||
} GinOptions;
|
||||
|
||||
#define GIN_DEFAULT_USE_FASTUPDATE true
|
||||
@@ -389,7 +389,7 @@ typedef struct
|
||||
{
|
||||
ItemPointerData first; /* first item in this posting list (unpacked) */
|
||||
uint16 nbytes; /* number of bytes that follow */
|
||||
unsigned char bytes[1]; /* varbyte encoded items (variable length) */
|
||||
unsigned char bytes[FLEXIBLE_ARRAY_MEMBER]; /* varbyte encoded items */
|
||||
} GinPostingList;
|
||||
|
||||
#define SizeOfGinPostingList(plist) (offsetof(GinPostingList, bytes) + SHORTALIGN((plist)->nbytes) )
|
||||
|
||||
@@ -47,7 +47,7 @@ typedef struct
|
||||
{
|
||||
BlockNumber prev;
|
||||
uint32 freespace;
|
||||
char tupledata[1];
|
||||
char tupledata[FLEXIBLE_ARRAY_MEMBER];
|
||||
} GISTNodeBufferPage;
|
||||
|
||||
#define BUFFER_PAGE_DATA_OFFSET MAXALIGN(offsetof(GISTNodeBufferPage, tupledata))
|
||||
@@ -131,7 +131,8 @@ typedef struct GISTSearchItem
|
||||
/* we must store parentlsn to detect whether a split occurred */
|
||||
GISTSearchHeapItem heap; /* heap info, if heap tuple */
|
||||
} data;
|
||||
double distances[1]; /* array with numberOfOrderBys entries */
|
||||
double distances[FLEXIBLE_ARRAY_MEMBER]; /* numberOfOrderBys
|
||||
* entries */
|
||||
} GISTSearchItem;
|
||||
|
||||
#define GISTSearchItemIsHeap(item) ((item).blkno == InvalidBlockNumber)
|
||||
@@ -144,7 +145,7 @@ typedef struct GISTSearchItem
|
||||
typedef struct GISTScanOpaqueData
|
||||
{
|
||||
GISTSTATE *giststate; /* index information, see above */
|
||||
pairingheap *queue; /* queue of unvisited items */
|
||||
pairingheap *queue; /* queue of unvisited items */
|
||||
MemoryContext queueCxt; /* context holding the queue */
|
||||
bool qual_ok; /* false if qual can never be satisfied */
|
||||
bool firstCall; /* true until first gistgettuple call */
|
||||
|
||||
@@ -132,7 +132,7 @@ typedef struct xl_heap_multi_insert
|
||||
{
|
||||
uint8 flags;
|
||||
uint16 ntuples;
|
||||
OffsetNumber offsets[1];
|
||||
OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER];
|
||||
} xl_heap_multi_insert;
|
||||
|
||||
#define SizeOfHeapMultiInsert offsetof(xl_heap_multi_insert, offsets)
|
||||
|
||||
@@ -426,7 +426,7 @@ typedef struct spgxlogMoveLeafs
|
||||
* the dead tuple from the source
|
||||
*----------
|
||||
*/
|
||||
OffsetNumber offsets[1];
|
||||
OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER];
|
||||
} spgxlogMoveLeafs;
|
||||
|
||||
#define SizeOfSpgxlogMoveLeafs offsetof(spgxlogMoveLeafs, offsets)
|
||||
@@ -534,7 +534,7 @@ typedef struct spgxlogPickSplit
|
||||
* list of leaf tuples, length nInsert (unaligned!)
|
||||
*----------
|
||||
*/
|
||||
OffsetNumber offsets[1];
|
||||
OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER];
|
||||
} spgxlogPickSplit;
|
||||
|
||||
#define SizeOfSpgxlogPickSplit offsetof(spgxlogPickSplit, offsets)
|
||||
@@ -558,7 +558,7 @@ typedef struct spgxlogVacuumLeaf
|
||||
* tuple numbers to insert in nextOffset links
|
||||
*----------
|
||||
*/
|
||||
OffsetNumber offsets[1];
|
||||
OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER];
|
||||
} spgxlogVacuumLeaf;
|
||||
|
||||
#define SizeOfSpgxlogVacuumLeaf offsetof(spgxlogVacuumLeaf, offsets)
|
||||
@@ -571,7 +571,7 @@ typedef struct spgxlogVacuumRoot
|
||||
spgxlogState stateSrc;
|
||||
|
||||
/* offsets of tuples to delete follow */
|
||||
OffsetNumber offsets[1];
|
||||
OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER];
|
||||
} spgxlogVacuumRoot;
|
||||
|
||||
#define SizeOfSpgxlogVacuumRoot offsetof(spgxlogVacuumRoot, offsets)
|
||||
@@ -583,7 +583,7 @@ typedef struct spgxlogVacuumRedirect
|
||||
TransactionId newestRedirectXid; /* newest XID of removed redirects */
|
||||
|
||||
/* offsets of redirect tuples to make placeholders follow */
|
||||
OffsetNumber offsets[1];
|
||||
OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER];
|
||||
} spgxlogVacuumRedirect;
|
||||
|
||||
#define SizeOfSpgxlogVacuumRedirect offsetof(spgxlogVacuumRedirect, offsets)
|
||||
|
||||
@@ -118,7 +118,7 @@ typedef struct xl_xact_assignment
|
||||
{
|
||||
TransactionId xtop; /* assigned XID's top-level XID */
|
||||
int nsubxacts; /* number of subtransaction XIDs */
|
||||
TransactionId xsub[1]; /* assigned subxids */
|
||||
TransactionId xsub[FLEXIBLE_ARRAY_MEMBER]; /* assigned subxids */
|
||||
} xl_xact_assignment;
|
||||
|
||||
#define MinSizeOfXactAssignment offsetof(xl_xact_assignment, xsub)
|
||||
@@ -128,7 +128,7 @@ typedef struct xl_xact_commit_compact
|
||||
TimestampTz xact_time; /* time of commit */
|
||||
int nsubxacts; /* number of subtransaction XIDs */
|
||||
/* ARRAY OF COMMITTED SUBTRANSACTION XIDs FOLLOWS */
|
||||
TransactionId subxacts[1]; /* VARIABLE LENGTH ARRAY */
|
||||
TransactionId subxacts[FLEXIBLE_ARRAY_MEMBER];
|
||||
} xl_xact_commit_compact;
|
||||
|
||||
#define MinSizeOfXactCommitCompact offsetof(xl_xact_commit_compact, subxacts)
|
||||
@@ -143,7 +143,7 @@ typedef struct xl_xact_commit
|
||||
Oid dbId; /* MyDatabaseId */
|
||||
Oid tsId; /* MyDatabaseTableSpace */
|
||||
/* Array of RelFileNode(s) to drop at commit */
|
||||
RelFileNode xnodes[1]; /* VARIABLE LENGTH ARRAY */
|
||||
RelFileNode xnodes[FLEXIBLE_ARRAY_MEMBER];
|
||||
/* ARRAY OF COMMITTED SUBTRANSACTION XIDs FOLLOWS */
|
||||
/* ARRAY OF SHARED INVALIDATION MESSAGES FOLLOWS */
|
||||
} xl_xact_commit;
|
||||
@@ -171,7 +171,7 @@ typedef struct xl_xact_abort
|
||||
int nrels; /* number of RelFileNodes */
|
||||
int nsubxacts; /* number of subtransaction XIDs */
|
||||
/* Array of RelFileNode(s) to drop at abort */
|
||||
RelFileNode xnodes[1]; /* VARIABLE LENGTH ARRAY */
|
||||
RelFileNode xnodes[FLEXIBLE_ARRAY_MEMBER];
|
||||
/* ARRAY OF ABORTED SUBTRANSACTION XIDs FOLLOWS */
|
||||
} xl_xact_abort;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user