@@ -237,8 +237,8 @@ typedef struct AsyncQueueControl
237
237
QueuePosition tail ; /* the global tail is equivalent to the tail
238
238
* of the "slowest" backend */
239
239
TimestampTz lastQueueFillWarn ; /* time of last queue-full msg */
240
- QueueBackendStatus backend [1 ]; /* actually of length MaxBackends+1 */
241
- /* DO NOT ADD FURTHER STRUCT MEMBERS HERE */
240
+ QueueBackendStatus backend [FLEXIBLE_ARRAY_MEMBER ];
241
+ /* backend[0] is not used; used entries are from [1] to [MaxBackends] */
242
242
} AsyncQueueControl ;
243
243
244
244
static AsyncQueueControl * asyncQueueControl ;
@@ -303,7 +303,7 @@ typedef enum
303
303
typedef struct
304
304
{
305
305
ListenActionKind action ;
306
- char channel [1 ]; /* actually, as long as needed */
306
+ char channel [FLEXIBLE_ARRAY_MEMBER ]; /* nul-terminated string */
307
307
} ListenAction ;
308
308
309
309
static List * pendingActions = NIL ; /* list of ListenAction */
@@ -417,8 +417,8 @@ AsyncShmemSize(void)
417
417
Size size ;
418
418
419
419
/* 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 ));
422
422
423
423
size = add_size (size , SimpleLruShmemSize (NUM_ASYNC_BUFFERS , 0 ));
424
424
@@ -438,12 +438,11 @@ AsyncShmemInit(void)
438
438
/*
439
439
* Create or attach to the AsyncQueueControl structure.
440
440
*
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.
444
443
*/
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 ));
447
446
448
447
asyncQueueControl = (AsyncQueueControl * )
449
448
ShmemInitStruct ("Async Queue Control" , size , & found );
@@ -605,7 +604,8 @@ queue_listen(ListenActionKind action, const char *channel)
605
604
oldcontext = MemoryContextSwitchTo (CurTransactionContext );
606
605
607
606
/* 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 );
609
609
actrec -> action = action ;
610
610
strcpy (actrec -> channel , channel );
611
611
0 commit comments