From: Tom Lane Date: Fri, 17 Dec 2004 20:58:47 +0000 (+0000) Subject: array_map failed to insert correct result type in an empty array. X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=69c619c365a68479ddbf148f5eccea3955ae225b;p=users%2Fbernd%2Fpostgres.git array_map failed to insert correct result type in an empty array. Per example from Florian Pflug. --- diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c index 6bafe0d314..5c7563466c 100644 --- a/src/backend/utils/adt/arrayfuncs.c +++ b/src/backend/utils/adt/arrayfuncs.c @@ -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; }