Skip to content

Commit 33a3b03

Browse files
committed
Use FLEXIBLE_ARRAY_MEMBER in some more places.
Fix a batch of structs that are only visible within individual .c files. Michael Paquier
1 parent c110eff commit 33a3b03

File tree

11 files changed

+32
-37
lines changed

11 files changed

+32
-37
lines changed

src/backend/access/nbtree/nbtutils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,7 +1836,7 @@ typedef struct BTVacInfo
18361836
BTCycleId cycle_ctr; /* cycle ID most recently assigned */
18371837
int num_vacuums; /* number of currently active VACUUMs */
18381838
int max_vacuums; /* allocated length of vacuums[] array */
1839-
BTOneVacInfo vacuums[1]; /* VARIABLE LENGTH ARRAY */
1839+
BTOneVacInfo vacuums[FLEXIBLE_ARRAY_MEMBER];
18401840
} BTVacInfo;
18411841

18421842
static BTVacInfo *btvacinfo;
@@ -1984,7 +1984,7 @@ BTreeShmemSize(void)
19841984
{
19851985
Size size;
19861986

1987-
size = offsetof(BTVacInfo, vacuums[0]);
1987+
size = offsetof(BTVacInfo, vacuums);
19881988
size = add_size(size, mul_size(MaxBackends, sizeof(BTOneVacInfo)));
19891989
return size;
19901990
}

src/backend/access/transam/multixact.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ typedef struct MultiXactStateData
258258
* stored in pg_control and used as truncation point for pg_multixact. At
259259
* checkpoint or restartpoint, unneeded segments are removed.
260260
*/
261-
MultiXactId perBackendXactIds[1]; /* VARIABLE LENGTH ARRAY */
261+
MultiXactId perBackendXactIds[FLEXIBLE_ARRAY_MEMBER];
262262
} MultiXactStateData;
263263

264264
/*
@@ -1744,8 +1744,9 @@ MultiXactShmemSize(void)
17441744
{
17451745
Size size;
17461746

1747+
/* We need 2*MaxOldestSlot + 1 perBackendXactIds[] entries */
17471748
#define SHARED_MULTIXACT_STATE_SIZE \
1748-
add_size(sizeof(MultiXactStateData), \
1749+
add_size(offsetof(MultiXactStateData, perBackendXactIds) + sizeof(MultiXactId), \
17491750
mul_size(sizeof(MultiXactId) * 2, MaxOldestSlot))
17501751

17511752
size = SHARED_MULTIXACT_STATE_SIZE;

src/backend/access/transam/twophase.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,9 @@ typedef struct TwoPhaseStateData
134134
/* Number of valid prepXacts entries. */
135135
int numPrepXacts;
136136

137-
/*
138-
* There are max_prepared_xacts items in this array, but C wants a
139-
* fixed-size array.
140-
*/
141-
GlobalTransaction prepXacts[1]; /* VARIABLE LENGTH ARRAY */
142-
} TwoPhaseStateData; /* VARIABLE LENGTH STRUCT */
137+
/* There are max_prepared_xacts items in this array */
138+
GlobalTransaction prepXacts[FLEXIBLE_ARRAY_MEMBER];
139+
} TwoPhaseStateData;
143140

144141
static TwoPhaseStateData *TwoPhaseState;
145142

src/backend/commands/tablespace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ GetDefaultTablespace(char relpersistence)
10881088
typedef struct
10891089
{
10901090
int numSpcs;
1091-
Oid tblSpcs[1]; /* VARIABLE LENGTH ARRAY */
1091+
Oid tblSpcs[FLEXIBLE_ARRAY_MEMBER];
10921092
} temp_tablespaces_extra;
10931093

10941094
/* check_hook: validate new temp_tablespaces */

src/backend/commands/trigger.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3005,7 +3005,7 @@ typedef struct SetConstraintStateData
30053005
bool all_isdeferred;
30063006
int numstates; /* number of trigstates[] entries in use */
30073007
int numalloc; /* allocated size of trigstates[] */
3008-
SetConstraintTriggerData trigstates[1]; /* VARIABLE LENGTH ARRAY */
3008+
SetConstraintTriggerData trigstates[FLEXIBLE_ARRAY_MEMBER];
30093009
} SetConstraintStateData;
30103010

30113011
typedef SetConstraintStateData *SetConstraintState;
@@ -4398,8 +4398,8 @@ SetConstraintStateCreate(int numalloc)
43984398
*/
43994399
state = (SetConstraintState)
44004400
MemoryContextAllocZero(TopTransactionContext,
4401-
sizeof(SetConstraintStateData) +
4402-
(numalloc - 1) *sizeof(SetConstraintTriggerData));
4401+
offsetof(SetConstraintStateData, trigstates) +
4402+
numalloc * sizeof(SetConstraintTriggerData));
44034403

44044404
state->numalloc = numalloc;
44054405

@@ -4440,8 +4440,8 @@ SetConstraintStateAddItem(SetConstraintState state,
44404440
newalloc = Max(newalloc, 8); /* in case original has size 0 */
44414441
state = (SetConstraintState)
44424442
repalloc(state,
4443-
sizeof(SetConstraintStateData) +
4444-
(newalloc - 1) *sizeof(SetConstraintTriggerData));
4443+
offsetof(SetConstraintStateData, trigstates) +
4444+
newalloc * sizeof(SetConstraintTriggerData));
44454445
state->numalloc = newalloc;
44464446
Assert(state->numstates < state->numalloc);
44474447
}

src/backend/executor/nodeAgg.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,9 @@ typedef struct AggHashEntryData *AggHashEntry;
297297
typedef struct AggHashEntryData
298298
{
299299
TupleHashEntryData shared; /* common header for hash table entries */
300-
/* per-aggregate transition status array - must be last! */
301-
AggStatePerGroupData pergroup[1]; /* VARIABLE LENGTH ARRAY */
302-
} AggHashEntryData; /* VARIABLE LENGTH STRUCT */
300+
/* per-aggregate transition status array */
301+
AggStatePerGroupData pergroup[FLEXIBLE_ARRAY_MEMBER];
302+
} AggHashEntryData;
303303

304304

305305
static void initialize_aggregates(AggState *aggstate,
@@ -941,8 +941,8 @@ build_hash_table(AggState *aggstate)
941941
Assert(node->aggstrategy == AGG_HASHED);
942942
Assert(node->numGroups > 0);
943943

944-
entrysize = sizeof(AggHashEntryData) +
945-
(aggstate->numaggs - 1) * sizeof(AggStatePerGroupData);
944+
entrysize = offsetof(AggHashEntryData, pergroup) +
945+
aggstate->numaggs * sizeof(AggStatePerGroupData);
946946

947947
aggstate->hashtable = BuildTupleHashTable(node->numCols,
948948
node->grpColIdx,
@@ -1013,8 +1013,8 @@ hash_agg_entry_size(int numAggs)
10131013
Size entrysize;
10141014

10151015
/* This must match build_hash_table */
1016-
entrysize = sizeof(AggHashEntryData) +
1017-
(numAggs - 1) * sizeof(AggStatePerGroupData);
1016+
entrysize = offsetof(AggHashEntryData, pergroup) +
1017+
numAggs * sizeof(AggStatePerGroupData);
10181018
entrysize = MAXALIGN(entrysize);
10191019
/* Account for hashtable overhead (assuming fill factor = 1) */
10201020
entrysize += 3 * sizeof(void *);

src/backend/postmaster/checkpointer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ typedef struct
130130

131131
int num_requests; /* current # of requests */
132132
int max_requests; /* allocated array size */
133-
CheckpointerRequest requests[1]; /* VARIABLE LENGTH ARRAY */
133+
CheckpointerRequest requests[FLEXIBLE_ARRAY_MEMBER];
134134
} CheckpointerShmemStruct;
135135

136136
static CheckpointerShmemStruct *CheckpointerShmem;

src/backend/storage/ipc/pmsignal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct PMSignalData
6666
/* per-child-process flags */
6767
int num_child_flags; /* # of entries in PMChildFlags[] */
6868
int next_child_flag; /* next slot to try to assign */
69-
sig_atomic_t PMChildFlags[1]; /* VARIABLE LENGTH ARRAY */
69+
sig_atomic_t PMChildFlags[FLEXIBLE_ARRAY_MEMBER];
7070
};
7171

7272
NON_EXEC_STATIC volatile PMSignalData *PMSignalState = NULL;

src/backend/storage/ipc/procarray.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,8 @@ typedef struct ProcArrayStruct
9090
/* oldest catalog xmin of any replication slot */
9191
TransactionId replication_slot_catalog_xmin;
9292

93-
/*
94-
* We declare pgprocnos[] as 1 entry because C wants a fixed-size array,
95-
* but actually it is maxProcs entries long.
96-
*/
97-
int pgprocnos[1]; /* VARIABLE LENGTH ARRAY */
93+
/* indexes into allPgXact[], has PROCARRAY_MAXPROCS entries */
94+
int pgprocnos[FLEXIBLE_ARRAY_MEMBER];
9895
} ProcArrayStruct;
9996

10097
static ProcArrayStruct *procArray;

src/backend/utils/cache/inval.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ typedef struct InvalidationChunk
122122
struct InvalidationChunk *next; /* list link */
123123
int nitems; /* # items currently stored in chunk */
124124
int maxitems; /* size of allocated array in this chunk */
125-
SharedInvalidationMessage msgs[1]; /* VARIABLE LENGTH ARRAY */
126-
} InvalidationChunk; /* VARIABLE LENGTH STRUCTURE */
125+
SharedInvalidationMessage msgs[FLEXIBLE_ARRAY_MEMBER];
126+
} InvalidationChunk;
127127

128128
typedef struct InvalidationListHeader
129129
{
@@ -225,8 +225,8 @@ AddInvalidationMessage(InvalidationChunk **listHdr,
225225
#define FIRSTCHUNKSIZE 32
226226
chunk = (InvalidationChunk *)
227227
MemoryContextAlloc(CurTransactionContext,
228-
sizeof(InvalidationChunk) +
229-
(FIRSTCHUNKSIZE - 1) *sizeof(SharedInvalidationMessage));
228+
offsetof(InvalidationChunk, msgs) +
229+
FIRSTCHUNKSIZE * sizeof(SharedInvalidationMessage));
230230
chunk->nitems = 0;
231231
chunk->maxitems = FIRSTCHUNKSIZE;
232232
chunk->next = *listHdr;
@@ -239,8 +239,8 @@ AddInvalidationMessage(InvalidationChunk **listHdr,
239239

240240
chunk = (InvalidationChunk *)
241241
MemoryContextAlloc(CurTransactionContext,
242-
sizeof(InvalidationChunk) +
243-
(chunksize - 1) *sizeof(SharedInvalidationMessage));
242+
offsetof(InvalidationChunk, msgs) +
243+
chunksize * sizeof(SharedInvalidationMessage));
244244
chunk->nitems = 0;
245245
chunk->maxitems = chunksize;
246246
chunk->next = *listHdr;

src/backend/utils/cache/typcache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ typedef struct TypeCacheEnumData
9393
Oid bitmap_base; /* OID corresponding to bit 0 of bitmapset */
9494
Bitmapset *sorted_values; /* Set of OIDs known to be in order */
9595
int num_values; /* total number of values in enum */
96-
EnumItem enum_values[1]; /* VARIABLE LENGTH ARRAY */
96+
EnumItem enum_values[FLEXIBLE_ARRAY_MEMBER];
9797
} TypeCacheEnumData;
9898

9999
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy