aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/arrayutils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils/adt/arrayutils.c')
-rw-r--r--src/backend/utils/adt/arrayutils.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/backend/utils/adt/arrayutils.c b/src/backend/utils/adt/arrayutils.c
index 051169a149a..3821f6637b6 100644
--- a/src/backend/utils/adt/arrayutils.c
+++ b/src/backend/utils/adt/arrayutils.c
@@ -75,6 +75,16 @@ ArrayGetOffset0(int n, const int *tup, const int *scale)
int
ArrayGetNItems(int ndim, const int *dims)
{
+ return ArrayGetNItemsSafe(ndim, dims, NULL);
+}
+
+/*
+ * This entry point can return the error into an ErrorSaveContext
+ * instead of throwing an exception. -1 is returned after an error.
+ */
+int
+ArrayGetNItemsSafe(int ndim, const int *dims, struct Node *escontext)
+{
int32 ret;
int i;
@@ -89,7 +99,7 @@ ArrayGetNItems(int ndim, const int *dims)
/* A negative dimension implies that UB-LB overflowed ... */
if (dims[i] < 0)
- ereport(ERROR,
+ ereturn(escontext, -1,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("array size exceeds the maximum allowed (%d)",
(int) MaxArraySize)));
@@ -98,14 +108,14 @@ ArrayGetNItems(int ndim, const int *dims)
ret = (int32) prod;
if ((int64) ret != prod)
- ereport(ERROR,
+ ereturn(escontext, -1,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("array size exceeds the maximum allowed (%d)",
(int) MaxArraySize)));
}
Assert(ret >= 0);
if ((Size) ret > MaxArraySize)
- ereport(ERROR,
+ ereturn(escontext, -1,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("array size exceeds the maximum allowed (%d)",
(int) MaxArraySize)));
@@ -127,6 +137,17 @@ ArrayGetNItems(int ndim, const int *dims)
void
ArrayCheckBounds(int ndim, const int *dims, const int *lb)
{
+ (void) ArrayCheckBoundsSafe(ndim, dims, lb, NULL);
+}
+
+/*
+ * This entry point can return the error into an ErrorSaveContext
+ * instead of throwing an exception.
+ */
+bool
+ArrayCheckBoundsSafe(int ndim, const int *dims, const int *lb,
+ struct Node *escontext)
+{
int i;
for (i = 0; i < ndim; i++)
@@ -135,11 +156,13 @@ ArrayCheckBounds(int ndim, const int *dims, const int *lb)
int32 sum PG_USED_FOR_ASSERTS_ONLY;
if (pg_add_s32_overflow(dims[i], lb[i], &sum))
- ereport(ERROR,
+ ereturn(escontext, false,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("array lower bound is too large: %d",
lb[i])));
}
+
+ return true;
}
/*