From 8ef289dba12f16f3692c235863a887672499a5d9 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 19 Nov 2005 03:00:09 +0000 Subject: Defend against nulls-in-arrays in contrib/intarray. I may have put in more tests than strictly necessary, but did not feel like tracing call paths in detail ... --- contrib/intarray/_int.h | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'contrib/intarray/_int.h') diff --git a/contrib/intarray/_int.h b/contrib/intarray/_int.h index 702dfaade53..ec09b149733 100644 --- a/contrib/intarray/_int.h +++ b/contrib/intarray/_int.h @@ -19,13 +19,24 @@ /* useful macros for accessing int4 arrays */ #define ARRPTR(x) ( (int4 *) ARR_DATA_PTR(x) ) -#define ARRNELEMS(x) ArrayGetNItems( ARR_NDIM(x), ARR_DIMS(x)) +#define ARRNELEMS(x) ArrayGetNItems(ARR_NDIM(x), ARR_DIMS(x)) -#define ARRISVOID(x) ( (x) ? ( ( ARR_NDIM(x) == NDIM ) ? ( ( ARRNELEMS( x ) ) ? 0 : 1 ) : ( ( ARR_NDIM(x) ) ? ( \ - ereport(ERROR, \ - (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), \ - errmsg("array must be one-dimensional, not %d dimensions", ARRNELEMS( x )))) \ - ,1) : 0 ) ) : 0 ) +/* reject arrays we can't handle; but allow a NULL or empty array */ +#define CHECKARRVALID(x) \ + do { \ + if (x) { \ + if (ARR_NDIM(x) != NDIM && ARR_NDIM(x) != 0) \ + ereport(ERROR, \ + (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), \ + errmsg("array must be one-dimensional"))); \ + if (ARR_HASNULL(x)) \ + ereport(ERROR, \ + (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), \ + errmsg("array must not contain nulls"))); \ + } \ + } while(0) + +#define ARRISVOID(x) ((x) == NULL || ARRNELEMS(x) == 0) #define SORT(x) \ do { \ @@ -52,9 +63,6 @@ typedef char BITVEC[SIGLEN]; typedef char *BITVECP; -#define SIGPTR(x) ( (BITVECP) ARR_DATA_PTR(x) ) - - #define LOOPBYTE(a) \ for(i=0;i