]> granicus.if.org Git - postgresql/commitdiff
Some more FLEXIBLE_ARRAY_MEMBER fixes.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 21 Feb 2015 06:46:43 +0000 (01:46 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 21 Feb 2015 06:46:43 +0000 (01:46 -0500)
src/backend/optimizer/plan/setrefs.c
src/include/access/brin_page.h
src/include/replication/slot.h
src/interfaces/libpq/fe-exec.c
src/interfaces/libpq/libpq-int.h
src/pl/plpgsql/src/pl_funcs.c
src/pl/plpgsql/src/plpgsql.h

index 57195e5d68ff8e1563d03b69acf693cceafca900..ec828cdd9fb808a254d9255afc7d5049376e406a 100644 (file)
@@ -41,9 +41,8 @@ typedef struct
        int                     num_vars;               /* number of plain Var tlist entries */
        bool            has_ph_vars;    /* are there PlaceHolderVar entries? */
        bool            has_non_vars;   /* are there other entries? */
-       /* array of num_vars entries: */
-       tlist_vinfo vars[1];            /* VARIABLE LENGTH ARRAY */
-} indexed_tlist;                               /* VARIABLE LENGTH STRUCT */
+       tlist_vinfo vars[FLEXIBLE_ARRAY_MEMBER];        /* has num_vars entries */
+} indexed_tlist;
 
 typedef struct
 {
index d8fa190912daad1a793ad5b81466f630233753b1..44ce5f6d1a41d7c55043b4da2eeef30b3b4b72ef 100644 (file)
@@ -56,7 +56,12 @@ typedef struct BrinMetaPageData
 /* Definitions for revmap pages */
 typedef struct RevmapContents
 {
-       ItemPointerData rm_tids[1]; /* really REVMAP_PAGE_MAXITEMS */
+       /*
+        * This array will fill all available space on the page.  It should be
+        * declared [FLEXIBLE_ARRAY_MEMBER], but for some reason you can't do that
+        * in an otherwise-empty struct.
+        */
+       ItemPointerData rm_tids[1];
 } RevmapContents;
 
 #define REVMAP_CONTENT_SIZE \
index d22963d0309ba88988c941924891f9256fbb5a79..a4001360c43bcf7210a6231e6444b3a7c3424c6d 100644 (file)
@@ -130,6 +130,10 @@ typedef struct ReplicationSlot
  */
 typedef struct ReplicationSlotCtlData
 {
+       /*
+        * This array should be declared [FLEXIBLE_ARRAY_MEMBER], but for some
+        * reason you can't do that in an otherwise-empty struct.
+        */
        ReplicationSlot replication_slots[1];
 } ReplicationSlotCtlData;
 
index 691202894fa06bcfa1ff60e62079ec57b57fae66..3d46e15067847d7ef410f21924b71a4edaaa909a 100644 (file)
@@ -892,7 +892,8 @@ pqSaveMessageField(PGresult *res, char code, const char *value)
 
        pfield = (PGMessageField *)
                pqResultAlloc(res,
-                                         sizeof(PGMessageField) + strlen(value),
+                                         offsetof(PGMessageField, contents) +
+                                         strlen(value) + 1,
                                          TRUE);
        if (!pfield)
                return;                                 /* out of memory? */
index 008fd67c5bf155e0c401eea7f63b3bd5a8f05dfd..64579d294044b3558cd91617592a19364eb66be2 100644 (file)
@@ -145,7 +145,7 @@ typedef struct pgMessageField
 {
        struct pgMessageField *next;    /* list link */
        char            code;                   /* field code */
-       char            contents[1];    /* field value (VARIABLE LENGTH) */
+       char            contents[FLEXIBLE_ARRAY_MEMBER];                /* value, nul-terminated */
 } PGMessageField;
 
 /* Fields needed for notice handling */
@@ -637,7 +637,7 @@ extern void pq_reset_sigpipe(sigset_t *osigset, bool sigpipe_pending,
  * The SSL implementatation provides these functions (fe-secure-openssl.c)
  */
 extern void pgtls_init_library(bool do_ssl, int do_crypto);
-extern int pgtls_init(PGconn *conn);
+extern int     pgtls_init(PGconn *conn);
 extern PostgresPollingStatusType pgtls_open_client(PGconn *conn);
 extern void pgtls_close(PGconn *conn);
 extern ssize_t pgtls_read(PGconn *conn, void *ptr, size_t len);
index 1dcea731e99b795aeebe7fff2273f2cebd9578b4..b6023cc0144e7f02744f7733bf7ab271cc6c2a73 100644 (file)
@@ -97,7 +97,7 @@ plpgsql_ns_additem(int itemtype, int itemno, const char *name)
        /* first item added must be a label */
        Assert(ns_top != NULL || itemtype == PLPGSQL_NSTYPE_LABEL);
 
-       nse = palloc(sizeof(PLpgSQL_nsitem) + strlen(name));
+       nse = palloc(offsetof(PLpgSQL_nsitem, name) +strlen(name) + 1);
        nse->itemtype = itemtype;
        nse->itemno = itemno;
        nse->prev = ns_top;
index 00f2f773a2965e631fd4a81ab7d18fa4c2e876e9..337b98980af965c3d80f555d27fd1b1341a2fef6 100644 (file)
@@ -329,7 +329,7 @@ typedef struct PLpgSQL_nsitem
        int                     itemtype;
        int                     itemno;
        struct PLpgSQL_nsitem *prev;
-       char            name[1];                /* actually, as long as needed */
+       char            name[FLEXIBLE_ARRAY_MEMBER];    /* nul-terminated string */
 } PLpgSQL_nsitem;