Skip to content

Commit e38b1eb

Browse files
committed
Use FLEXIBLE_ARRAY_MEMBER in struct varlena.
This forces some minor coding adjustments in tuptoaster.c and inv_api.c, but the new coding there is cleaner anyway. Michael Paquier
1 parent 8902f79 commit e38b1eb

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/backend/access/heap/tuptoaster.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,11 +1365,13 @@ toast_save_datum(Relation rel, Datum value,
13651365
CommandId mycid = GetCurrentCommandId(true);
13661366
struct varlena *result;
13671367
struct varatt_external toast_pointer;
1368-
struct
1368+
union
13691369
{
13701370
struct varlena hdr;
1371-
char data[TOAST_MAX_CHUNK_SIZE]; /* make struct big enough */
1372-
int32 align_it; /* ensure struct is aligned well enough */
1371+
/* this is to make the union big enough for a chunk: */
1372+
char data[TOAST_MAX_CHUNK_SIZE + VARHDRSZ];
1373+
/* ensure union is aligned well enough: */
1374+
int32 align_it;
13731375
} chunk_data;
13741376
int32 chunk_size;
13751377
int32 chunk_seq = 0;

src/backend/storage/large_object/inv_api.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -562,11 +562,13 @@ inv_write(LargeObjectDesc *obj_desc, const char *buf, int nbytes)
562562
bool neednextpage;
563563
bytea *datafield;
564564
bool pfreeit;
565-
struct
565+
union
566566
{
567567
bytea hdr;
568-
char data[LOBLKSIZE]; /* make struct big enough */
569-
int32 align_it; /* ensure struct is aligned well enough */
568+
/* this is to make the union big enough for a LO data chunk: */
569+
char data[LOBLKSIZE + VARHDRSZ];
570+
/* ensure union is aligned well enough: */
571+
int32 align_it;
570572
} workbuf;
571573
char *workb = VARDATA(&workbuf.hdr);
572574
HeapTuple newtup;
@@ -748,11 +750,13 @@ inv_truncate(LargeObjectDesc *obj_desc, int64 len)
748750
SysScanDesc sd;
749751
HeapTuple oldtuple;
750752
Form_pg_largeobject olddata;
751-
struct
753+
union
752754
{
753755
bytea hdr;
754-
char data[LOBLKSIZE]; /* make struct big enough */
755-
int32 align_it; /* ensure struct is aligned well enough */
756+
/* this is to make the union big enough for a LO data chunk: */
757+
char data[LOBLKSIZE + VARHDRSZ];
758+
/* ensure union is aligned well enough: */
759+
int32 align_it;
756760
} workbuf;
757761
char *workb = VARDATA(&workbuf.hdr);
758762
HeapTuple newtup;

src/include/c.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ typedef struct
391391
struct varlena
392392
{
393393
char vl_len_[4]; /* Do not touch this field directly! */
394-
char vl_dat[1];
394+
char vl_dat[FLEXIBLE_ARRAY_MEMBER]; /* Data content is here */
395395
};
396396

397397
#define VARHDRSZ ((int32) sizeof(int32))

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