Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bd3bc40

Browse files
committed
array_map failed to insert correct result type in an empty array.
Per example from Florian Pflug.
1 parent 92c001b commit bd3bc40

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/backend/utils/adt/arrayfuncs.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.113 2004/09/27 01:39:02 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.114 2004/12/17 20:58:26 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2241,7 +2241,13 @@ array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType)
22412241

22422242
/* Check for empty array */
22432243
if (nitems <= 0)
2244-
PG_RETURN_ARRAYTYPE_P(v);
2244+
{
2245+
/* Return empty array */
2246+
result = (ArrayType *) palloc0(sizeof(ArrayType));
2247+
result->size = sizeof(ArrayType);
2248+
result->elemtype = retType;
2249+
PG_RETURN_ARRAYTYPE_P(result);
2250+
}
22452251

22462252
/*
22472253
* We arrange to look up info about input and return element types
@@ -2425,14 +2431,9 @@ construct_md_array(Datum *elems,
24252431
if (ndims == 0)
24262432
{
24272433
/* Allocate and initialize 0-D result array */
2428-
nbytes = ARR_OVERHEAD(ndims);
2429-
result = (ArrayType *) palloc(nbytes);
2430-
2431-
result->size = nbytes;
2432-
result->ndim = ndims;
2433-
result->flags = 0;
2434+
result = (ArrayType *) palloc0(sizeof(ArrayType));
2435+
result->size = sizeof(ArrayType);
24342436
result->elemtype = elmtype;
2435-
24362437
return result;
24372438
}
24382439

0 commit comments

Comments
 (0)