From a62c4cc8ede6600f8ae636dfe9f56c6fd119c638 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Thu, 19 Feb 2015 14:02:14 +0900 Subject: [PATCH 3/4] Switch varlena to use FLEXIBLE_ARRAY_MEMBER As compilers normally complain about a flexible-array element not at the end of a structure (clang does, while gcc sometimes does not), this has needed some modifications in structures using bytea as such. This commit ensures as well that those structures have enough room to work as intended as well. --- src/backend/access/heap/tuptoaster.c | 4 ++-- src/backend/storage/large_object/inv_api.c | 8 ++++---- src/include/c.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/backend/access/heap/tuptoaster.c b/src/backend/access/heap/tuptoaster.c index f8c1401..547f21f 100644 --- a/src/backend/access/heap/tuptoaster.c +++ b/src/backend/access/heap/tuptoaster.c @@ -1365,10 +1365,10 @@ toast_save_datum(Relation rel, Datum value, CommandId mycid = GetCurrentCommandId(true); struct varlena *result; struct varatt_external toast_pointer; - struct + union { struct varlena hdr; - char data[TOAST_MAX_CHUNK_SIZE]; /* make struct big enough */ + char data[TOAST_MAX_CHUNK_SIZE + VARHDRSZ]; /* make struct big enough */ int32 align_it; /* ensure struct is aligned well enough */ } chunk_data; int32 chunk_size; diff --git a/src/backend/storage/large_object/inv_api.c b/src/backend/storage/large_object/inv_api.c index a19c401..2e877bc 100644 --- a/src/backend/storage/large_object/inv_api.c +++ b/src/backend/storage/large_object/inv_api.c @@ -562,10 +562,10 @@ inv_write(LargeObjectDesc *obj_desc, const char *buf, int nbytes) bool neednextpage; bytea *datafield; bool pfreeit; - struct + union { bytea hdr; - char data[LOBLKSIZE]; /* make struct big enough */ + char data[LOBLKSIZE + VARHDRSZ]; /* make struct big enough */ int32 align_it; /* ensure struct is aligned well enough */ } workbuf; char *workb = VARDATA(&workbuf.hdr); @@ -748,10 +748,10 @@ inv_truncate(LargeObjectDesc *obj_desc, int64 len) SysScanDesc sd; HeapTuple oldtuple; Form_pg_largeobject olddata; - struct + union { bytea hdr; - char data[LOBLKSIZE]; /* make struct big enough */ + char data[LOBLKSIZE + VARHDRSZ]; /* make struct big enough */ int32 align_it; /* ensure struct is aligned well enough */ } workbuf; char *workb = VARDATA(&workbuf.hdr); diff --git a/src/include/c.h b/src/include/c.h index bbd0d53..36ec468 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -391,7 +391,7 @@ typedef struct struct varlena { char vl_len_[4]; /* Do not touch this field directly! */ - char vl_dat[1]; + char vl_dat[FLEXIBLE_ARRAY_MEMBER]; }; #define VARHDRSZ ((int32) sizeof(int32)) -- 2.3.0