diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2004-12-17 20:58:26 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2004-12-17 20:58:26 +0000 |
commit | bd3bc4076e9fb701456acef2370237baab839583 (patch) | |
tree | 9eaf34cc8498be95394050844e863551123907e5 /src/backend/utils/adt/arrayfuncs.c | |
parent | 92c001bbaf86ac171fb361e81aa962ae873b52c2 (diff) | |
download | postgresql-bd3bc4076e9fb701456acef2370237baab839583.tar.gz postgresql-bd3bc4076e9fb701456acef2370237baab839583.zip |
array_map failed to insert correct result type in an empty array.
Per example from Florian Pflug.
Diffstat (limited to 'src/backend/utils/adt/arrayfuncs.c')
-rw-r--r-- | src/backend/utils/adt/arrayfuncs.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c index 0e2ed00be08..cee11cc0b67 100644 --- a/src/backend/utils/adt/arrayfuncs.c +++ b/src/backend/utils/adt/arrayfuncs.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.113 2004/09/27 01:39:02 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.114 2004/12/17 20:58:26 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -2241,7 +2241,13 @@ array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType) /* Check for empty array */ if (nitems <= 0) - PG_RETURN_ARRAYTYPE_P(v); + { + /* Return empty array */ + result = (ArrayType *) palloc0(sizeof(ArrayType)); + result->size = sizeof(ArrayType); + result->elemtype = retType; + PG_RETURN_ARRAYTYPE_P(result); + } /* * We arrange to look up info about input and return element types @@ -2425,14 +2431,9 @@ construct_md_array(Datum *elems, if (ndims == 0) { /* Allocate and initialize 0-D result array */ - nbytes = ARR_OVERHEAD(ndims); - result = (ArrayType *) palloc(nbytes); - - result->size = nbytes; - result->ndim = ndims; - result->flags = 0; + result = (ArrayType *) palloc0(sizeof(ArrayType)); + result->size = sizeof(ArrayType); result->elemtype = elmtype; - return result; } |