diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2015-02-20 00:11:42 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2015-02-20 00:11:42 -0500 |
commit | 09d8d110a604e52216102e73fb8475b7aa88f1d1 (patch) | |
tree | 6ffdaba34c52c319aa32b3cb95cc93cdcefb6d65 /src/backend/utils/adt/geo_ops.c | |
parent | 2fb7a75f37d0beca80f45e15736ec8d50064228a (diff) | |
download | postgresql-09d8d110a604e52216102e73fb8475b7aa88f1d1.tar.gz |
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.
Diffstat (limited to 'src/backend/utils/adt/geo_ops.c')
-rw-r--r-- | src/backend/utils/adt/geo_ops.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/backend/utils/adt/geo_ops.c b/src/backend/utils/adt/geo_ops.c index 6b6510e8e2..6cb6be5c5f 100644 --- a/src/backend/utils/adt/geo_ops.c +++ b/src/backend/utils/adt/geo_ops.c @@ -1390,7 +1390,7 @@ path_in(PG_FUNCTION_ARGS) } base_size = sizeof(path->p[0]) * npts; - size = offsetof(PATH, p[0]) +base_size; + size = offsetof(PATH, p) +base_size; /* Check for integer overflow */ if (base_size / npts != sizeof(path->p[0]) || size <= base_size) @@ -1443,12 +1443,12 @@ path_recv(PG_FUNCTION_ARGS) closed = pq_getmsgbyte(buf); npts = pq_getmsgint(buf, sizeof(int32)); - if (npts <= 0 || npts >= (int32) ((INT_MAX - offsetof(PATH, p[0])) / sizeof(Point))) + if (npts <= 0 || npts >= (int32) ((INT_MAX - offsetof(PATH, p)) / sizeof(Point))) ereport(ERROR, (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION), errmsg("invalid number of points in external \"path\" value"))); - size = offsetof(PATH, p[0]) +sizeof(path->p[0]) * npts; + size = offsetof(PATH, p) +sizeof(path->p[0]) * npts; path = (PATH *) palloc(size); SET_VARSIZE(path, size); @@ -3476,7 +3476,7 @@ poly_in(PG_FUNCTION_ARGS) errmsg("invalid input syntax for type polygon: \"%s\"", str))); base_size = sizeof(poly->p[0]) * npts; - size = offsetof(POLYGON, p[0]) +base_size; + size = offsetof(POLYGON, p) +base_size; /* Check for integer overflow */ if (base_size / npts != sizeof(poly->p[0]) || size <= base_size) @@ -3530,12 +3530,12 @@ poly_recv(PG_FUNCTION_ARGS) int size; npts = pq_getmsgint(buf, sizeof(int32)); - if (npts <= 0 || npts >= (int32) ((INT_MAX - offsetof(POLYGON, p[0])) / sizeof(Point))) + if (npts <= 0 || npts >= (int32) ((INT_MAX - offsetof(POLYGON, p)) / sizeof(Point))) ereport(ERROR, (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION), errmsg("invalid number of points in external \"polygon\" value"))); - size = offsetof(POLYGON, p[0]) +sizeof(poly->p[0]) * npts; + size = offsetof(POLYGON, p) +sizeof(poly->p[0]) * npts; poly = (POLYGON *) palloc0(size); /* zero any holes */ SET_VARSIZE(poly, size); @@ -4251,7 +4251,7 @@ path_add(PG_FUNCTION_ARGS) PG_RETURN_NULL(); base_size = sizeof(p1->p[0]) * (p1->npts + p2->npts); - size = offsetof(PATH, p[0]) +base_size; + size = offsetof(PATH, p) +base_size; /* Check for integer overflow */ if (base_size / sizeof(p1->p[0]) != (p1->npts + p2->npts) || @@ -4393,7 +4393,7 @@ path_poly(PG_FUNCTION_ARGS) * Never overflows: the old size fit in MaxAllocSize, and the new size is * just a small constant larger. */ - size = offsetof(POLYGON, p[0]) +sizeof(poly->p[0]) * path->npts; + size = offsetof(POLYGON, p) +sizeof(poly->p[0]) * path->npts; poly = (POLYGON *) palloc(size); SET_VARSIZE(poly, size); @@ -4468,7 +4468,7 @@ box_poly(PG_FUNCTION_ARGS) int size; /* map four corners of the box to a polygon */ - size = offsetof(POLYGON, p[0]) +sizeof(poly->p[0]) * 4; + size = offsetof(POLYGON, p) +sizeof(poly->p[0]) * 4; poly = (POLYGON *) palloc(size); SET_VARSIZE(poly, size); @@ -4502,7 +4502,7 @@ poly_path(PG_FUNCTION_ARGS) * Never overflows: the old size fit in MaxAllocSize, and the new size is * smaller by a small constant. */ - size = offsetof(PATH, p[0]) +sizeof(path->p[0]) * poly->npts; + size = offsetof(PATH, p) +sizeof(path->p[0]) * poly->npts; path = (PATH *) palloc(size); SET_VARSIZE(path, size); @@ -5181,7 +5181,7 @@ circle_poly(PG_FUNCTION_ARGS) errmsg("must request at least 2 points"))); base_size = sizeof(poly->p[0]) * npts; - size = offsetof(POLYGON, p[0]) +base_size; + size = offsetof(POLYGON, p) +base_size; /* Check for integer overflow */ if (base_size / npts != sizeof(poly->p[0]) || size <= base_size) |