Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2e21121

Browse files
committed
Use FLEXIBLE_ARRAY_MEMBER in a number of other places.
I think we're about done with this...
1 parente1a11d9 commit2e21121

File tree

14 files changed

+54
-62
lines changed

14 files changed

+54
-62
lines changed

‎contrib/hstore/hstore_gist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ typedef struct
4141
{
4242
int32vl_len_;/* varlena header (do not touch directly!) */
4343
int32flag;
44-
chardata[1];
44+
chardata[FLEXIBLE_ARRAY_MEMBER];
4545
}GISTTYPE;
4646

4747
#defineALLISTRUE0x04

‎contrib/spi/timetravel.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ static intnPlans = 0;
3535
typedefstruct_TTOffList
3636
{
3737
struct_TTOffList*next;
38-
charname[1];
38+
charname[FLEXIBLE_ARRAY_MEMBER];
3939
}TTOffList;
4040

41-
staticTTOffListTTOff={NULL, {0}};
41+
staticTTOffList*TTOff=NULL;
4242

4343
staticintfindTTStatus(char*name);
4444
staticEPlan*find_plan(char*ident,EPlan**eplan,int*nplans);
@@ -428,10 +428,11 @@ set_timetravel(PG_FUNCTION_ARGS)
428428
char*d;
429429
char*s;
430430
int32ret;
431-
TTOffList*p,
431+
TTOffList*prev,
432432
*pp;
433433

434-
for (pp= (p=&TTOff)->next;pp;pp= (p=pp)->next)
434+
prev=NULL;
435+
for (pp=TTOff;pp;prev=pp,pp=pp->next)
435436
{
436437
if (namestrcmp(relname,pp->name)==0)
437438
break;
@@ -442,7 +443,10 @@ set_timetravel(PG_FUNCTION_ARGS)
442443
if (on!=0)
443444
{
444445
/* turn ON */
445-
p->next=pp->next;
446+
if (prev)
447+
prev->next=pp->next;
448+
else
449+
TTOff=pp->next;
446450
free(pp);
447451
}
448452
ret=0;
@@ -456,15 +460,18 @@ set_timetravel(PG_FUNCTION_ARGS)
456460
s=rname=DatumGetCString(DirectFunctionCall1(nameout,NameGetDatum(relname)));
457461
if (s)
458462
{
459-
pp=malloc(sizeof(TTOffList)+strlen(rname));
463+
pp=malloc(offsetof(TTOffList,name)+strlen(rname)+1);
460464
if (pp)
461465
{
462466
pp->next=NULL;
463-
p->next=pp;
464467
d=pp->name;
465468
while (*s)
466469
*d++=tolower((unsignedchar)*s++);
467470
*d='\0';
471+
if (prev)
472+
prev->next=pp;
473+
else
474+
TTOff=pp;
468475
}
469476
pfree(rname);
470477
}
@@ -486,7 +493,7 @@ get_timetravel(PG_FUNCTION_ARGS)
486493
Namerelname=PG_GETARG_NAME(0);
487494
TTOffList*pp;
488495

489-
for (pp=TTOff.next;pp;pp=pp->next)
496+
for (pp=TTOff;pp;pp=pp->next)
490497
{
491498
if (namestrcmp(relname,pp->name)==0)
492499
PG_RETURN_INT32(0);
@@ -499,7 +506,7 @@ findTTStatus(char *name)
499506
{
500507
TTOffList*pp;
501508

502-
for (pp=TTOff.next;pp;pp=pp->next)
509+
for (pp=TTOff;pp;pp=pp->next)
503510
if (pg_strcasecmp(name,pp->name)==0)
504511
return0;
505512
return1;

‎src/backend/access/heap/syncscan.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,11 @@ typedef struct ss_scan_locations_t
103103
{
104104
ss_lru_item_t*head;
105105
ss_lru_item_t*tail;
106-
ss_lru_item_titems[1];/* SYNC_SCAN_NELEM items */
106+
ss_lru_item_titems[FLEXIBLE_ARRAY_MEMBER];/* SYNC_SCAN_NELEM items */
107107
}ss_scan_locations_t;
108108

109-
#defineSizeOfScanLocations(N) offsetof(ss_scan_locations_t, items[N])
109+
#defineSizeOfScanLocations(N) \
110+
(offsetof(ss_scan_locations_t, items) + (N) * sizeof(ss_lru_item_t))
110111

111112
/* Pointer to struct in shared memory */
112113
staticss_scan_locations_t*scan_locations;

‎src/backend/commands/async.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ typedef struct AsyncQueueControl
237237
QueuePositiontail;/* the global tail is equivalent to the tail
238238
* of the "slowest" backend */
239239
TimestampTzlastQueueFillWarn;/* time of last queue-full msg */
240-
QueueBackendStatusbackend[1];/* actually of length MaxBackends+1 */
241-
/*DO NOT ADD FURTHER STRUCT MEMBERS HERE */
240+
QueueBackendStatusbackend[FLEXIBLE_ARRAY_MEMBER];
241+
/*backend[0] is not used; used entries are from [1] to [MaxBackends] */
242242
}AsyncQueueControl;
243243

244244
staticAsyncQueueControl*asyncQueueControl;
@@ -303,7 +303,7 @@ typedef enum
303303
typedefstruct
304304
{
305305
ListenActionKindaction;
306-
charchannel[1];/*actually, as long as needed */
306+
charchannel[FLEXIBLE_ARRAY_MEMBER];/*nul-terminated string */
307307
}ListenAction;
308308

309309
staticList*pendingActions=NIL;/* list of ListenAction */
@@ -417,8 +417,8 @@ AsyncShmemSize(void)
417417
Sizesize;
418418

419419
/* This had better match AsyncShmemInit */
420-
size=mul_size(MaxBackends,sizeof(QueueBackendStatus));
421-
size=add_size(size,sizeof(AsyncQueueControl));
420+
size=mul_size(MaxBackends+1,sizeof(QueueBackendStatus));
421+
size=add_size(size,offsetof(AsyncQueueControl,backend));
422422

423423
size=add_size(size,SimpleLruShmemSize(NUM_ASYNC_BUFFERS,0));
424424

@@ -438,12 +438,11 @@ AsyncShmemInit(void)
438438
/*
439439
* Create or attach to the AsyncQueueControl structure.
440440
*
441-
* The used entries in the backend[] array run from 1 to MaxBackends.
442-
* sizeof(AsyncQueueControl) already includes space for the unused zero'th
443-
* entry, but we need to add on space for the used entries.
441+
* The used entries in the backend[] array run from 1 to MaxBackends; the
442+
* zero'th entry is unused but must be allocated.
444443
*/
445-
size=mul_size(MaxBackends,sizeof(QueueBackendStatus));
446-
size=add_size(size,sizeof(AsyncQueueControl));
444+
size=mul_size(MaxBackends+1,sizeof(QueueBackendStatus));
445+
size=add_size(size,offsetof(AsyncQueueControl,backend));
447446

448447
asyncQueueControl= (AsyncQueueControl*)
449448
ShmemInitStruct("Async Queue Control",size,&found);
@@ -605,7 +604,8 @@ queue_listen(ListenActionKind action, const char *channel)
605604
oldcontext=MemoryContextSwitchTo(CurTransactionContext);
606605

607606
/* space for terminating null is included in sizeof(ListenAction) */
608-
actrec= (ListenAction*)palloc(sizeof(ListenAction)+strlen(channel));
607+
actrec= (ListenAction*)palloc(offsetof(ListenAction,channel)+
608+
strlen(channel)+1);
609609
actrec->action=action;
610610
strcpy(actrec->channel,channel);
611611

‎src/backend/libpq/auth.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,7 +2172,7 @@ typedef struct
21722172
{
21732173
uint8attribute;
21742174
uint8length;
2175-
uint8data[1];
2175+
uint8data[FLEXIBLE_ARRAY_MEMBER];
21762176
}radius_attribute;
21772177

21782178
typedefstruct
@@ -2220,7 +2220,6 @@ radius_add_attribute(radius_packet *packet, uint8 type, const unsigned char *dat
22202220
"Adding attribute code %d with length %d to radius packet would create oversize packet, ignoring",
22212221
type,len);
22222222
return;
2223-
22242223
}
22252224

22262225
attr= (radius_attribute*) ((unsignedchar*)packet+packet->length);

‎src/backend/storage/buffer/freelist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ typedef struct BufferAccessStrategyData
9393
* simplicity this is palloc'd together with the fixed fields of the
9494
* struct.
9595
*/
96-
Bufferbuffers[1];/* VARIABLE SIZE ARRAY */
96+
Bufferbuffers[FLEXIBLE_ARRAY_MEMBER];
9797
}BufferAccessStrategyData;
9898

9999

‎src/backend/storage/ipc/sinvaladt.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,9 @@ typedef struct SISeg
184184
SharedInvalidationMessagebuffer[MAXNUMMESSAGES];
185185

186186
/*
187-
* Per-backend state info.
188-
*
189-
* We declare procState as 1 entry because C wants a fixed-size array, but
190-
* actually it is maxBackends entries long.
187+
* Per-backend invalidation state info (has MaxBackends entries).
191188
*/
192-
ProcStateprocState[1];/* reflects the invalidation state */
189+
ProcStateprocState[FLEXIBLE_ARRAY_MEMBER];
193190
}SISeg;
194191

195192
staticSISeg*shmInvalBuffer;/* pointer to the shared inval buffer */
@@ -221,16 +218,12 @@ SInvalShmemSize(void)
221218
void
222219
CreateSharedInvalidationState(void)
223220
{
224-
Sizesize;
225221
inti;
226222
boolfound;
227223

228224
/* Allocate space in shared memory */
229-
size= offsetof(SISeg,procState);
230-
size=add_size(size,mul_size(sizeof(ProcState),MaxBackends));
231-
232225
shmInvalBuffer= (SISeg*)
233-
ShmemInitStruct("shmInvalBuffer",size,&found);
226+
ShmemInitStruct("shmInvalBuffer",SInvalShmemSize(),&found);
234227
if (found)
235228
return;
236229

‎src/backend/utils/adt/numeric.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ typedef int16 NumericDigit;
123123
structNumericShort
124124
{
125125
uint16n_header;/* Sign + display scale + weight */
126-
NumericDigitn_data[1];/* Digits */
126+
NumericDigitn_data[FLEXIBLE_ARRAY_MEMBER];/* Digits */
127127
};
128128

129129
structNumericLong
130130
{
131131
uint16n_sign_dscale;/* Sign + display scale */
132132
int16n_weight;/* Weight of 1st digit*/
133-
NumericDigitn_data[1];/* Digits */
133+
NumericDigitn_data[FLEXIBLE_ARRAY_MEMBER];/* Digits */
134134
};
135135

136136
unionNumericChoice
@@ -1262,7 +1262,7 @@ numeric_floor(PG_FUNCTION_ARGS)
12621262
/*
12631263
* generate_series_numeric() -
12641264
*
1265-
*Generate series of numeric.
1265+
*Generate series of numeric.
12661266
*/
12671267
Datum
12681268
generate_series_numeric(PG_FUNCTION_ARGS)
@@ -1297,7 +1297,7 @@ generate_series_step_numeric(PG_FUNCTION_ARGS)
12971297
/* see if we were given an explicit step size */
12981298
if (PG_NARGS()==3)
12991299
{
1300-
Numericstep_num=PG_GETARG_NUMERIC(2);
1300+
Numericstep_num=PG_GETARG_NUMERIC(2);
13011301

13021302
if (NUMERIC_IS_NAN(step_num))
13031303
ereport(ERROR,
@@ -1356,7 +1356,7 @@ generate_series_step_numeric(PG_FUNCTION_ARGS)
13561356
(fctx->step.sign==NUMERIC_NEG&&
13571357
cmp_var(&fctx->current,&fctx->stop) >=0))
13581358
{
1359-
Numericresult=make_result(&fctx->current);
1359+
Numericresult=make_result(&fctx->current);
13601360

13611361
/* switch to memory context appropriate for iteration calculation */
13621362
oldcontext=MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);

‎src/backend/utils/adt/tsgistidx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ typedef struct
5050
{
5151
int32vl_len_;/* varlena header (do not touch directly!) */
5252
int32flag;
53-
chardata[1];
53+
chardata[FLEXIBLE_ARRAY_MEMBER];
5454
}SignTSVector;
5555

5656
#defineARRKEY0x01

‎src/backend/utils/adt/tsvector_op.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ typedef struct StatEntry
4444
structStatEntry*left;
4545
structStatEntry*right;
4646
uint32lenlexeme;
47-
charlexeme[1];
47+
charlexeme[FLEXIBLE_ARRAY_MEMBER];
4848
}StatEntry;
4949

5050
#defineSTATENTRYHDRSZ(offsetof(StatEntry, lexeme))

‎src/backend/utils/adt/txid.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ typedef struct
6464
uint32nxip;/* number of txids in xip array */
6565
txidxmin;
6666
txidxmax;
67-
txidxip[1];/* in-progress txids, xmin <= xip[i] < xmax */
67+
/* in-progress txids, xmin <= xip[i] < xmax: */
68+
txidxip[FLEXIBLE_ARRAY_MEMBER];
6869
}TxidSnapshot;
6970

7071
#defineTXID_SNAPSHOT_SIZE(nxip) \

‎src/backend/utils/fmgr/dfmgr.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,7 @@ typedef struct df_files
5151
ino_tinode;/* Inode number of file */
5252
#endif
5353
void*handle;/* a handle for pg_dl* functions */
54-
charfilename[1];/* Full pathname of file */
55-
56-
/*
57-
* we allocate the block big enough for actual length of pathname.
58-
* filename[] must be last item in struct!
59-
*/
54+
charfilename[FLEXIBLE_ARRAY_MEMBER];/* Full pathname of file */
6055
}DynamicFileList;
6156

6257
staticDynamicFileList*file_list=NULL;
@@ -217,13 +212,13 @@ internal_load_library(const char *libname)
217212
* File not loaded yet.
218213
*/
219214
file_scanner= (DynamicFileList*)
220-
malloc(sizeof(DynamicFileList)+strlen(libname));
215+
malloc(offsetof(DynamicFileList,filename)+strlen(libname)+1);
221216
if (file_scanner==NULL)
222217
ereport(ERROR,
223218
(errcode(ERRCODE_OUT_OF_MEMORY),
224219
errmsg("out of memory")));
225220

226-
MemSet(file_scanner,0,sizeof(DynamicFileList));
221+
MemSet(file_scanner,0,offsetof(DynamicFileList,filename));
227222
strcpy(file_scanner->filename,libname);
228223
file_scanner->device=stat_buf.st_dev;
229224
#ifndefWIN32

‎src/backend/utils/sort/logtape.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,9 @@ struct LogicalTapeSet
166166
intnFreeBlocks;/* # of currently free blocks */
167167
intfreeBlocksLen;/* current allocated length of freeBlocks[] */
168168

169-
/*
170-
* tapes[] is declared size 1 since C wants a fixed size, but actually it
171-
* is of length nTapes.
172-
*/
169+
/* The array of logical tapes. */
173170
intnTapes;/* # of logical tapes in set */
174-
LogicalTapetapes[1];/*must be last in struct! */
171+
LogicalTapetapes[FLEXIBLE_ARRAY_MEMBER];/*has nTapes nentries */
175172
};
176173

177174
staticvoidltsWriteBlock(LogicalTapeSet*lts,longblocknum,void*buffer);
@@ -519,12 +516,11 @@ LogicalTapeSetCreate(int ntapes)
519516
inti;
520517

521518
/*
522-
* Create top-level struct including per-tape LogicalTape structs. First
523-
* LogicalTape struct is already counted in sizeof(LogicalTapeSet).
519+
* Create top-level struct including per-tape LogicalTape structs.
524520
*/
525521
Assert(ntapes>0);
526-
lts= (LogicalTapeSet*)palloc(sizeof(LogicalTapeSet)+
527-
(ntapes-1)*sizeof(LogicalTape));
522+
lts= (LogicalTapeSet*)palloc(offsetof(LogicalTapeSet,tapes)+
523+
ntapes*sizeof(LogicalTape));
528524
lts->pfile=BufFileCreateTemp(false);
529525
lts->nFileBlocks=0L;
530526
lts->forgetFreeSpace= false;

‎src/interfaces/ecpg/ecpglib/extern.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ enum ARRAY_TYPE
3333
structECPGgeneric_varchar
3434
{
3535
intlen;
36-
chararr[1];
36+
chararr[FLEXIBLE_ARRAY_MEMBER];
3737
};
3838

3939
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp