Skip to content

Commit f2874fe

Browse files
committed
Some more FLEXIBLE_ARRAY_MEMBER fixes.
1 parent 33b2a2c commit f2874fe

File tree

7 files changed

+18
-9
lines changed

7 files changed

+18
-9
lines changed

src/backend/optimizer/plan/setrefs.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ typedef struct
4141
int num_vars; /* number of plain Var tlist entries */
4242
bool has_ph_vars; /* are there PlaceHolderVar entries? */
4343
bool has_non_vars; /* are there other entries? */
44-
/* array of num_vars entries: */
45-
tlist_vinfo vars[1]; /* VARIABLE LENGTH ARRAY */
46-
} indexed_tlist; /* VARIABLE LENGTH STRUCT */
44+
tlist_vinfo vars[FLEXIBLE_ARRAY_MEMBER]; /* has num_vars entries */
45+
} indexed_tlist;
4746

4847
typedef struct
4948
{

src/include/access/brin_page.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ typedef struct BrinMetaPageData
5656
/* Definitions for revmap pages */
5757
typedef struct RevmapContents
5858
{
59-
ItemPointerData rm_tids[1]; /* really REVMAP_PAGE_MAXITEMS */
59+
/*
60+
* This array will fill all available space on the page. It should be
61+
* declared [FLEXIBLE_ARRAY_MEMBER], but for some reason you can't do that
62+
* in an otherwise-empty struct.
63+
*/
64+
ItemPointerData rm_tids[1];
6065
} RevmapContents;
6166

6267
#define REVMAP_CONTENT_SIZE \

src/include/replication/slot.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ typedef struct ReplicationSlot
130130
*/
131131
typedef struct ReplicationSlotCtlData
132132
{
133+
/*
134+
* This array should be declared [FLEXIBLE_ARRAY_MEMBER], but for some
135+
* reason you can't do that in an otherwise-empty struct.
136+
*/
133137
ReplicationSlot replication_slots[1];
134138
} ReplicationSlotCtlData;
135139

src/interfaces/libpq/fe-exec.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,8 @@ pqSaveMessageField(PGresult *res, char code, const char *value)
892892

893893
pfield = (PGMessageField *)
894894
pqResultAlloc(res,
895-
sizeof(PGMessageField) + strlen(value),
895+
offsetof(PGMessageField, contents) +
896+
strlen(value) + 1,
896897
TRUE);
897898
if (!pfield)
898899
return; /* out of memory? */

src/interfaces/libpq/libpq-int.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ typedef struct pgMessageField
145145
{
146146
struct pgMessageField *next; /* list link */
147147
char code; /* field code */
148-
char contents[1]; /* field value (VARIABLE LENGTH) */
148+
char contents[FLEXIBLE_ARRAY_MEMBER]; /* value, nul-terminated */
149149
} PGMessageField;
150150

151151
/* Fields needed for notice handling */
@@ -637,7 +637,7 @@ extern void pq_reset_sigpipe(sigset_t *osigset, bool sigpipe_pending,
637637
* The SSL implementatation provides these functions (fe-secure-openssl.c)
638638
*/
639639
extern void pgtls_init_library(bool do_ssl, int do_crypto);
640-
extern int pgtls_init(PGconn *conn);
640+
extern int pgtls_init(PGconn *conn);
641641
extern PostgresPollingStatusType pgtls_open_client(PGconn *conn);
642642
extern void pgtls_close(PGconn *conn);
643643
extern ssize_t pgtls_read(PGconn *conn, void *ptr, size_t len);

src/pl/plpgsql/src/pl_funcs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ plpgsql_ns_additem(int itemtype, int itemno, const char *name)
9797
/* first item added must be a label */
9898
Assert(ns_top != NULL || itemtype == PLPGSQL_NSTYPE_LABEL);
9999

100-
nse = palloc(sizeof(PLpgSQL_nsitem) + strlen(name));
100+
nse = palloc(offsetof(PLpgSQL_nsitem, name) +strlen(name) + 1);
101101
nse->itemtype = itemtype;
102102
nse->itemno = itemno;
103103
nse->prev = ns_top;

src/pl/plpgsql/src/plpgsql.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ typedef struct PLpgSQL_nsitem
329329
int itemtype;
330330
int itemno;
331331
struct PLpgSQL_nsitem *prev;
332-
char name[1]; /* actually, as long as needed */
332+
char name[FLEXIBLE_ARRAY_MEMBER]; /* nul-terminated string */
333333
} PLpgSQL_nsitem;
334334

335335

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