Use FLEXIBLE_ARRAY_MEMBER in a bunch more places.

Tom Lane <tgl@sss.pgh.pa.us>

Commit: 09d8d110a604e52216102e73fb8475b7aa88f1d1
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: 2015-02-20T05:11:42Z
Releases: 9.5.0
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.

Files

PathChange+/−
contrib/cube/cubedata.h modified +7 −8
contrib/intarray/_int.h modified +2 −2
contrib/ltree/ltree.h modified +7 −7
contrib/pageinspect/rawpage.c modified +1 −1
contrib/pg_trgm/trgm.h modified +1 −1
src/backend/catalog/namespace.c modified +7 −6
src/backend/commands/prepare.c modified +2 −3
src/backend/executor/functions.c modified +3 −3
src/backend/executor/spi.c modified +2 −3
src/backend/nodes/params.c modified +2 −3
src/backend/postmaster/syslogger.c modified +2 −2
src/backend/tcop/postgres.c modified +2 −3
src/backend/utils/adt/geo_ops.c modified +11 −11
src/backend/utils/cache/catcache.c modified +1 −1
src/bin/pg_dump/dumputils.c modified +1 −2
src/bin/pg_dump/dumputils.h modified +1 −1
src/include/access/gin_private.h modified +2 −2
src/include/access/gist_private.h modified +4 −3
src/include/access/heapam_xlog.h modified +1 −1
src/include/access/spgist_private.h modified +5 −5
src/include/access/xact.h modified +4 −4
src/include/catalog/namespace.h modified +2 −2
src/include/c.h modified +4 −4
src/include/commands/dbcommands.h modified +0 −15
src/include/commands/tablespace.h modified +1 −1
src/include/executor/hashjoin.h modified +1 −1
src/include/nodes/bitmapset.h modified +2 −2
src/include/nodes/params.h modified +1 −1
src/include/nodes/tidbitmap.h modified +2 −2
src/include/postgres.h modified +4 −4
src/include/postmaster/syslogger.h modified +1 −1
src/include/replication/walsender_private.h modified +2 −2
src/include/storage/bufpage.h modified +1 −1
src/include/storage/fsm_internals.h modified +1 −1
src/include/storage/standby.h modified +2 −2
src/include/tsearch/dicts/regis.h modified +1 −1
src/include/tsearch/dicts/spell.h modified +3 −3
src/include/tsearch/ts_type.h modified +3 −3
src/include/utils/catcache.h modified +2 −2
src/include/utils/datetime.h modified +2 −2
src/include/utils/geo_decls.h modified +2 −2
src/include/utils/jsonb.h modified +1 −1
src/include/utils/relmapper.h modified +1 −1
src/include/utils/varbit.h modified +2 −1