Commit bd3bc407 authored by Tom Lane's avatar Tom Lane

array_map failed to insert correct result type in an empty array.

Per example from Florian Pflug.
parent 92c001bb
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -2241,7 +2241,13 @@ array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType)
/* Check for empty array */ /* Check for empty array */
if (nitems <= 0) 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 * We arrange to look up info about input and return element types
...@@ -2425,14 +2431,9 @@ construct_md_array(Datum *elems, ...@@ -2425,14 +2431,9 @@ construct_md_array(Datum *elems,
if (ndims == 0) if (ndims == 0)
{ {
/* Allocate and initialize 0-D result array */ /* Allocate and initialize 0-D result array */
nbytes = ARR_OVERHEAD(ndims); result = (ArrayType *) palloc0(sizeof(ArrayType));
result = (ArrayType *) palloc(nbytes); result->size = sizeof(ArrayType);
result->size = nbytes;
result->ndim = ndims;
result->flags = 0;
result->elemtype = elmtype; result->elemtype = elmtype;
return result; return result;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment