aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/arrayfuncs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils/adt/arrayfuncs.c')
-rw-r--r--src/backend/utils/adt/arrayfuncs.c24
1 files changed, 9 insertions, 15 deletions
diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c
index b2beb18bc5f..f34ee3b773e 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.141 2008/02/29 20:58:33 alvherre Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.142 2008/03/25 22:42:43 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1533,39 +1533,33 @@ Datum
array_dims(PG_FUNCTION_ARGS)
{
ArrayType *v = PG_GETARG_ARRAYTYPE_P(0);
- text *result;
char *p;
- int nbytes,
- i;
+ int i;
int *dimv,
*lb;
- /* Sanity check: does it look like an array at all? */
- if (ARR_NDIM(v) <= 0 || ARR_NDIM(v) > MAXDIM)
- PG_RETURN_NULL();
-
- nbytes = ARR_NDIM(v) * 33 + 1;
-
/*
* 33 since we assume 15 digits per number + ':' +'[]'
*
- * +1 allows for temp trailing null
+ * +1 for trailing null
*/
+ char buf[MAXDIM * 33 + 1];
- result = (text *) palloc(nbytes + VARHDRSZ);
- p = VARDATA(result);
+ /* Sanity check: does it look like an array at all? */
+ if (ARR_NDIM(v) <= 0 || ARR_NDIM(v) > MAXDIM)
+ PG_RETURN_NULL();
dimv = ARR_DIMS(v);
lb = ARR_LBOUND(v);
+ p = buf;
for (i = 0; i < ARR_NDIM(v); i++)
{
sprintf(p, "[%d:%d]", lb[i], dimv[i] + lb[i] - 1);
p += strlen(p);
}
- SET_VARSIZE(result, strlen(VARDATA(result)) + VARHDRSZ);
- PG_RETURN_TEXT_P(result);
+ PG_RETURN_TEXT_P(cstring_to_text(buf));
}
/*