mirror of
https://github.com/postgres/postgres.git
synced 2025-08-21 10:42:50 +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:
@@ -21,7 +21,7 @@ typedef struct RegisNode
|
||||
len:16,
|
||||
unused:14;
|
||||
struct RegisNode *next;
|
||||
unsigned char data[1];
|
||||
unsigned char data[FLEXIBLE_ARRAY_MEMBER];
|
||||
} RegisNode;
|
||||
|
||||
#define RNHDRSZ (offsetof(RegisNode,data))
|
||||
|
@@ -49,7 +49,7 @@ typedef struct
|
||||
typedef struct SPNode
|
||||
{
|
||||
uint32 length;
|
||||
SPNodeData data[1];
|
||||
SPNodeData data[FLEXIBLE_ARRAY_MEMBER];
|
||||
} SPNode;
|
||||
|
||||
#define SPNHDRSZ (offsetof(SPNode,data))
|
||||
@@ -70,7 +70,7 @@ typedef struct spell_struct
|
||||
int len;
|
||||
} d;
|
||||
} p;
|
||||
char word[1]; /* variable length, null-terminated */
|
||||
char word[FLEXIBLE_ARRAY_MEMBER];
|
||||
} SPELL;
|
||||
|
||||
#define SPELLHDRSZ (offsetof(SPELL, word))
|
||||
@@ -120,7 +120,7 @@ typedef struct AffixNode
|
||||
{
|
||||
uint32 isvoid:1,
|
||||
length:31;
|
||||
AffixNodeData data[1];
|
||||
AffixNodeData data[FLEXIBLE_ARRAY_MEMBER];
|
||||
} AffixNode;
|
||||
|
||||
#define ANHRDSZ (offsetof(AffixNode, data))
|
||||
|
@@ -63,7 +63,7 @@ typedef uint16 WordEntryPos;
|
||||
typedef struct
|
||||
{
|
||||
uint16 npos;
|
||||
WordEntryPos pos[1]; /* variable length */
|
||||
WordEntryPos pos[FLEXIBLE_ARRAY_MEMBER];
|
||||
} WordEntryPosVector;
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ typedef struct
|
||||
{
|
||||
int32 vl_len_; /* varlena header (do not touch directly!) */
|
||||
int32 size;
|
||||
WordEntry entries[1]; /* variable length */
|
||||
WordEntry entries[FLEXIBLE_ARRAY_MEMBER];
|
||||
/* lexemes follow the entries[] array */
|
||||
} TSVectorData;
|
||||
|
||||
@@ -233,7 +233,7 @@ typedef struct
|
||||
{
|
||||
int32 vl_len_; /* varlena header (do not touch directly!) */
|
||||
int32 size; /* number of QueryItems */
|
||||
char data[1]; /* data starts here */
|
||||
char data[FLEXIBLE_ARRAY_MEMBER]; /* data starts here */
|
||||
} TSQueryData;
|
||||
|
||||
typedef TSQueryData *TSQuery;
|
||||
|
Reference in New Issue
Block a user