mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
Use FLEXIBLE_ARRAY_MEMBER in a bunch more places.
Replace some bogus "x[1]" declarations with "x[FLEXIBLE_ARRAY_MEMBER]". Aside from being more self-documenting, this should help prevent bogus warnings from static code analyzers and perhaps compiler misoptimizations. This patch is just a down payment on eliminating the whole problem, but it gets rid of a lot of easy-to-fix cases. Note that the main problem with doing this is that one must no longer rely on computing sizeof(the containing struct), since the result would be compiler-dependent. Instead use offsetof(struct, lastfield). Autoconf also warns against spelling that offsetof(struct, lastfield[0]). Michael Paquier, review and additional fixes by me.
This commit is contained in:
@ -23,11 +23,10 @@ typedef struct NDBOX
|
||||
unsigned int header;
|
||||
|
||||
/*
|
||||
* Variable length array. The lower left coordinates for each dimension
|
||||
* come first, followed by upper right coordinates unless the point flag
|
||||
* is set.
|
||||
* The lower left coordinates for each dimension come first, followed by
|
||||
* upper right coordinates unless the point flag is set.
|
||||
*/
|
||||
double x[1];
|
||||
double x[FLEXIBLE_ARRAY_MEMBER];
|
||||
} NDBOX;
|
||||
|
||||
#define POINT_BIT 0x80000000
|
||||
@ -41,9 +40,9 @@ typedef struct NDBOX
|
||||
#define LL_COORD(cube, i) ( (cube)->x[i] )
|
||||
#define UR_COORD(cube, i) ( IS_POINT(cube) ? (cube)->x[i] : (cube)->x[(i) + DIM(cube)] )
|
||||
|
||||
#define POINT_SIZE(_dim) (offsetof(NDBOX, x[0]) + sizeof(double)*(_dim))
|
||||
#define CUBE_SIZE(_dim) (offsetof(NDBOX, x[0]) + sizeof(double)*(_dim)*2)
|
||||
#define POINT_SIZE(_dim) (offsetof(NDBOX, x) + sizeof(double)*(_dim))
|
||||
#define CUBE_SIZE(_dim) (offsetof(NDBOX, x) + sizeof(double)*(_dim)*2)
|
||||
|
||||
#define DatumGetNDBOX(x) ((NDBOX*)DatumGetPointer(x))
|
||||
#define PG_GETARG_NDBOX(x) DatumGetNDBOX( PG_DETOAST_DATUM(PG_GETARG_DATUM(x)) )
|
||||
#define DatumGetNDBOX(x) ((NDBOX *) PG_DETOAST_DATUM(x))
|
||||
#define PG_GETARG_NDBOX(x) DatumGetNDBOX(PG_GETARG_DATUM(x))
|
||||
#define PG_RETURN_NDBOX(x) PG_RETURN_POINTER(x)
|
||||
|
@ -73,7 +73,7 @@ typedef struct
|
||||
{
|
||||
int32 vl_len_; /* varlena header (do not touch directly!) */
|
||||
int32 flag;
|
||||
char data[1];
|
||||
char data[FLEXIBLE_ARRAY_MEMBER];
|
||||
} GISTTYPE;
|
||||
|
||||
#define ALLISTRUE 0x04
|
||||
@ -133,7 +133,7 @@ typedef struct QUERYTYPE
|
||||
{
|
||||
int32 vl_len_; /* varlena header (do not touch directly!) */
|
||||
int32 size; /* number of ITEMs */
|
||||
ITEM items[1]; /* variable length array */
|
||||
ITEM items[FLEXIBLE_ARRAY_MEMBER];
|
||||
} QUERYTYPE;
|
||||
|
||||
#define HDRSIZEQT offsetof(QUERYTYPE, items)
|
||||
|
@ -10,7 +10,7 @@
|
||||
typedef struct
|
||||
{
|
||||
uint16 len;
|
||||
char name[1];
|
||||
char name[FLEXIBLE_ARRAY_MEMBER];
|
||||
} ltree_level;
|
||||
|
||||
#define LEVEL_HDRSIZE (offsetof(ltree_level,name))
|
||||
@ -20,7 +20,7 @@ typedef struct
|
||||
{
|
||||
int32 vl_len_; /* varlena header (do not touch directly!) */
|
||||
uint16 numlevel;
|
||||
char data[1];
|
||||
char data[FLEXIBLE_ARRAY_MEMBER];
|
||||
} ltree;
|
||||
|
||||
#define LTREE_HDRSIZE MAXALIGN( offsetof(ltree, data) )
|
||||
@ -34,7 +34,7 @@ typedef struct
|
||||
int32 val;
|
||||
uint16 len;
|
||||
uint8 flag;
|
||||
char name[1];
|
||||
char name[FLEXIBLE_ARRAY_MEMBER];
|
||||
} lquery_variant;
|
||||
|
||||
#define LVAR_HDRSIZE MAXALIGN(offsetof(lquery_variant, name))
|
||||
@ -51,7 +51,7 @@ typedef struct
|
||||
uint16 numvar;
|
||||
uint16 low;
|
||||
uint16 high;
|
||||
char variants[1];
|
||||
char variants[FLEXIBLE_ARRAY_MEMBER];
|
||||
} lquery_level;
|
||||
|
||||
#define LQL_HDRSIZE MAXALIGN( offsetof(lquery_level,variants) )
|
||||
@ -72,7 +72,7 @@ typedef struct
|
||||
uint16 numlevel;
|
||||
uint16 firstgood;
|
||||
uint16 flag;
|
||||
char data[1];
|
||||
char data[FLEXIBLE_ARRAY_MEMBER];
|
||||
} lquery;
|
||||
|
||||
#define LQUERY_HDRSIZE MAXALIGN( offsetof(lquery, data) )
|
||||
@ -107,7 +107,7 @@ typedef struct
|
||||
{
|
||||
int32 vl_len_; /* varlena header (do not touch directly!) */
|
||||
int32 size;
|
||||
char data[1];
|
||||
char data[FLEXIBLE_ARRAY_MEMBER];
|
||||
} ltxtquery;
|
||||
|
||||
#define HDRSIZEQT MAXALIGN(VARHDRSZ + sizeof(int32))
|
||||
@ -208,7 +208,7 @@ typedef struct
|
||||
{
|
||||
int32 vl_len_; /* varlena header (do not touch directly!) */
|
||||
uint32 flag;
|
||||
char data[1];
|
||||
char data[FLEXIBLE_ARRAY_MEMBER];
|
||||
} ltree_gist;
|
||||
|
||||
#define LTG_ONENODE 0x01
|
||||
|
@ -192,7 +192,7 @@ page_header(PG_FUNCTION_ARGS)
|
||||
* Check that enough data was supplied, so that we don't try to access
|
||||
* fields outside the supplied buffer.
|
||||
*/
|
||||
if (raw_page_size < sizeof(PageHeaderData))
|
||||
if (raw_page_size < SizeOfPageHeaderData)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("input page too small (%d bytes)", raw_page_size)));
|
||||
|
@ -63,7 +63,7 @@ typedef struct
|
||||
{
|
||||
int32 vl_len_; /* varlena header (do not touch directly!) */
|
||||
uint8 flag;
|
||||
char data[1];
|
||||
char data[FLEXIBLE_ARRAY_MEMBER];
|
||||
} TRGM;
|
||||
|
||||
#define TRGMHDRSIZE (VARHDRSZ + sizeof(uint8))
|
||||
|
Reference in New Issue
Block a user