From d0ee93797d9c06e619b3f382705d99ee195bb573 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Sat, 1 Feb 2014 10:49:17 -0500 Subject: [PATCH] arrays: tighten checks for multi-dimensional input Previously an input array string that started with a single-element array dimension would then later accept a multi-dimensional segment. BACKWARD INCOMPATIBILITY --- src/backend/utils/adt/arrayfuncs.c | 8 ++++---- src/test/regress/expected/arrays.out | 2 +- src/test/regress/sql/arrays.sql | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c index 311d0c22f0..91df184242 100644 --- a/src/backend/utils/adt/arrayfuncs.c +++ b/src/backend/utils/adt/arrayfuncs.c @@ -425,8 +425,8 @@ ArrayCount(const char *str, int *dim, char typdelim) for (i = 0; i < MAXDIM; ++i) { - temp[i] = dim[i] = 0; - nelems_last[i] = nelems[i] = 1; + temp[i] = dim[i] = nelems_last[i] = 0; + nelems[i] = 1; } ptr = str; @@ -540,8 +540,8 @@ ArrayCount(const char *str, int *dim, char typdelim) errmsg("malformed array literal: \"%s\"", str))); nest_level--; - if ((nelems_last[nest_level] != 1) && - (nelems[nest_level] != nelems_last[nest_level])) + if (nelems_last[nest_level] != 0 && + nelems[nest_level] != nelems_last[nest_level]) ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("multidimensional arrays must have " diff --git a/src/test/regress/expected/arrays.out b/src/test/regress/expected/arrays.out index e1b9d7f0a8..6dce5c9301 100644 --- a/src/test/regress/expected/arrays.out +++ b/src/test/regress/expected/arrays.out @@ -1491,7 +1491,7 @@ select cardinality('{{1,2},{3,4},{5,6}}'::int[]); 6 (1 row) -select cardinality('{{{1}},{{2,3},{3,4}}}'::int[]); +select cardinality('{{{1,9},{5,6}},{{2,3},{3,4}}}'::int[]); cardinality ------------- 8 diff --git a/src/test/regress/sql/arrays.sql b/src/test/regress/sql/arrays.sql index 64630d9ab7..92af172dfc 100644 --- a/src/test/regress/sql/arrays.sql +++ b/src/test/regress/sql/arrays.sql @@ -425,7 +425,7 @@ select cardinality(array[1,2,3]); select cardinality('[2:4]={5,6,7}'::int[]); select cardinality('{{1,2}}'::int[]); select cardinality('{{1,2},{3,4},{5,6}}'::int[]); -select cardinality('{{{1}},{{2,3},{3,4}}}'::int[]); +select cardinality('{{{1,9},{5,6}},{{2,3},{3,4}}}'::int[]); select array_agg(unique1) from (select unique1 from tenk1 where unique1 < 15 order by unique1) ss; select array_agg(ten) from (select ten from tenk1 where unique1 < 15 order by unique1) ss;