diff options
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/catalog/namespace.c | 13 | ||||
-rw-r--r-- | src/backend/commands/prepare.c | 5 | ||||
-rw-r--r-- | src/backend/executor/functions.c | 6 | ||||
-rw-r--r-- | src/backend/executor/spi.c | 5 | ||||
-rw-r--r-- | src/backend/nodes/params.c | 5 | ||||
-rw-r--r-- | src/backend/postmaster/syslogger.c | 4 | ||||
-rw-r--r-- | src/backend/tcop/postgres.c | 5 | ||||
-rw-r--r-- | src/backend/utils/adt/geo_ops.c | 22 | ||||
-rw-r--r-- | src/backend/utils/cache/catcache.c | 2 |
9 files changed, 32 insertions, 35 deletions
diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c index bfb4fdcc668..1af977cb1d7 100644 --- a/src/backend/catalog/namespace.c +++ b/src/backend/catalog/namespace.c @@ -261,9 +261,9 @@ RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode, * with the answer changing under them, or that they already hold some * appropriate lock, and therefore return the first answer we get without * checking for invalidation messages. Also, if the requested lock is - * already held, LockRelationOid will not AcceptInvalidationMessages, - * so we may fail to notice a change. We could protect against that case - * by calling AcceptInvalidationMessages() before beginning this loop, but + * already held, LockRelationOid will not AcceptInvalidationMessages, so + * we may fail to notice a change. We could protect against that case by + * calling AcceptInvalidationMessages() before beginning this loop, but * that would add a significant amount overhead, so for now we don't. */ for (;;) @@ -1075,8 +1075,8 @@ FuncnameGetCandidates(List *names, int nargs, List *argnames, */ effective_nargs = Max(pronargs, nargs); newResult = (FuncCandidateList) - palloc(sizeof(struct _FuncCandidateList) - sizeof(Oid) - + effective_nargs * sizeof(Oid)); + palloc(offsetof(struct _FuncCandidateList, args) + + effective_nargs * sizeof(Oid)); newResult->pathpos = pathpos; newResult->oid = HeapTupleGetOid(proctup); newResult->nargs = effective_nargs; @@ -1597,7 +1597,8 @@ OpernameGetCandidates(List *names, char oprkind, bool missing_schema_ok) * separate palloc for each operator, but profiling revealed that the * pallocs used an unreasonably large fraction of parsing time. */ -#define SPACE_PER_OP MAXALIGN(sizeof(struct _FuncCandidateList) + sizeof(Oid)) +#define SPACE_PER_OP MAXALIGN(offsetof(struct _FuncCandidateList, args) + \ + 2 * sizeof(Oid)) if (catlist->n_members > 0) resultSpace = palloc(catlist->n_members * SPACE_PER_OP); diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c index 71b08f01bf3..fb33d305aff 100644 --- a/src/backend/commands/prepare.c +++ b/src/backend/commands/prepare.c @@ -383,10 +383,9 @@ EvaluateParams(PreparedStatement *pstmt, List *params, /* Prepare the expressions for execution */ exprstates = (List *) ExecPrepareExpr((Expr *) params, estate); - /* sizeof(ParamListInfoData) includes the first array element */ paramLI = (ParamListInfo) - palloc(sizeof(ParamListInfoData) + - (num_params - 1) * sizeof(ParamExternData)); + palloc(offsetof(ParamListInfoData, params) + + num_params * sizeof(ParamExternData)); /* we have static list of params, so no hooks needed */ paramLI->paramFetch = NULL; paramLI->paramFetchArg = NULL; diff --git a/src/backend/executor/functions.c b/src/backend/executor/functions.c index 84be37c7a39..6c3eff7c584 100644 --- a/src/backend/executor/functions.c +++ b/src/backend/executor/functions.c @@ -896,9 +896,9 @@ postquel_sub_params(SQLFunctionCachePtr fcache, if (fcache->paramLI == NULL) { - /* sizeof(ParamListInfoData) includes the first array element */ - paramLI = (ParamListInfo) palloc(sizeof(ParamListInfoData) + - (nargs - 1) * sizeof(ParamExternData)); + paramLI = (ParamListInfo) + palloc(offsetof(ParamListInfoData, params) + + nargs * sizeof(ParamExternData)); /* we have static list of params, so no hooks needed */ paramLI->paramFetch = NULL; paramLI->paramFetchArg = NULL; diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c index 4b86e910df8..b3c05025bc0 100644 --- a/src/backend/executor/spi.c +++ b/src/backend/executor/spi.c @@ -2290,9 +2290,8 @@ _SPI_convert_params(int nargs, Oid *argtypes, { int i; - /* sizeof(ParamListInfoData) includes the first array element */ - paramLI = (ParamListInfo) palloc(sizeof(ParamListInfoData) + - (nargs - 1) * sizeof(ParamExternData)); + paramLI = (ParamListInfo) palloc(offsetof(ParamListInfoData, params) + + nargs * sizeof(ParamExternData)); /* we have static list of params, so no hooks needed */ paramLI->paramFetch = NULL; paramLI->paramFetchArg = NULL; diff --git a/src/backend/nodes/params.c b/src/backend/nodes/params.c index 2f2f5edb832..fb803f8ee8b 100644 --- a/src/backend/nodes/params.c +++ b/src/backend/nodes/params.c @@ -40,9 +40,8 @@ copyParamList(ParamListInfo from) if (from == NULL || from->numParams <= 0) return NULL; - /* sizeof(ParamListInfoData) includes the first array element */ - size = sizeof(ParamListInfoData) + - (from->numParams - 1) * sizeof(ParamExternData); + size = offsetof(ParamListInfoData, params) + + from->numParams * sizeof(ParamExternData); retval = (ParamListInfo) palloc(size); retval->paramFetch = NULL; diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c index 41b8dbb6c25..14ff1477c16 100644 --- a/src/backend/postmaster/syslogger.c +++ b/src/backend/postmaster/syslogger.c @@ -785,13 +785,13 @@ process_pipe_input(char *logbuffer, int *bytes_in_logbuffer) int dest = LOG_DESTINATION_STDERR; /* While we have enough for a header, process data... */ - while (count >= (int) sizeof(PipeProtoHeader)) + while (count >= (int) (offsetof(PipeProtoHeader, data) +1)) { PipeProtoHeader p; int chunklen; /* Do we have a valid header? */ - memcpy(&p, cursor, sizeof(PipeProtoHeader)); + memcpy(&p, cursor, offsetof(PipeProtoHeader, data)); if (p.nuls[0] == '\0' && p.nuls[1] == '\0' && p.len > 0 && p.len <= PIPE_MAX_PAYLOAD && p.pid != 0 && diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 28af40c3dc6..33720e8f8b8 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -1619,9 +1619,8 @@ exec_bind_message(StringInfo input_message) { int paramno; - /* sizeof(ParamListInfoData) includes the first array element */ - params = (ParamListInfo) palloc(sizeof(ParamListInfoData) + - (numParams - 1) * sizeof(ParamExternData)); + params = (ParamListInfo) palloc(offsetof(ParamListInfoData, params) + + numParams * sizeof(ParamExternData)); /* we have static list of params, so no hooks needed */ params->paramFetch = NULL; params->paramFetchArg = NULL; diff --git a/src/backend/utils/adt/geo_ops.c b/src/backend/utils/adt/geo_ops.c index 6b6510e8e2a..6cb6be5c5fd 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) diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c index 2e4d0b393a3..1af43c6de67 100644 --- a/src/backend/utils/cache/catcache.c +++ b/src/backend/utils/cache/catcache.c @@ -1590,7 +1590,7 @@ SearchCatCacheList(CatCache *cache, oldcxt = MemoryContextSwitchTo(CacheMemoryContext); nmembers = list_length(ctlist); cl = (CatCList *) - palloc(sizeof(CatCList) + nmembers * sizeof(CatCTup *)); + palloc(offsetof(CatCList, members) +nmembers * sizeof(CatCTup *)); heap_copytuple_with_tuple(ntp, &cl->tuple); MemoryContextSwitchTo(oldcxt); heap_freetuple(ntp); |