aboutsummaryrefslogtreecommitdiff
path: root/contrib/intarray/_int_tool.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2005-11-19 03:00:09 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2005-11-19 03:00:09 +0000
commit8ef289dba12f16f3692c235863a887672499a5d9 (patch)
tree819abde06463716dbbf505c444a69ec6858efe6a /contrib/intarray/_int_tool.c
parent25c00833cb694bea1c4fb3caeccbc9a1fb72d6f8 (diff)
downloadpostgresql-8ef289dba12f16f3692c235863a887672499a5d9.tar.gz
postgresql-8ef289dba12f16f3692c235863a887672499a5d9.zip
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 ...
Diffstat (limited to 'contrib/intarray/_int_tool.c')
-rw-r--r--contrib/intarray/_int_tool.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/contrib/intarray/_int_tool.c b/contrib/intarray/_int_tool.c
index 13c5d1e9e24..480e16ed9fe 100644
--- a/contrib/intarray/_int_tool.c
+++ b/contrib/intarray/_int_tool.c
@@ -12,6 +12,9 @@ inner_int_contains(ArrayType *a, ArrayType *b)
int *da,
*db;
+ CHECKARRVALID(a);
+ CHECKARRVALID(b);
+
if (ARRISVOID(a) || ARRISVOID(b))
return FALSE;
@@ -46,6 +49,9 @@ inner_int_overlap(ArrayType *a, ArrayType *b)
int *da,
*db;
+ CHECKARRVALID(a);
+ CHECKARRVALID(b);
+
if (ARRISVOID(a) || ARRISVOID(b))
return FALSE;
@@ -78,6 +84,9 @@ inner_int_union(ArrayType *a, ArrayType *b)
int i,
j;
+ CHECKARRVALID(a);
+ CHECKARRVALID(b);
+
if (ARRISVOID(a) && ARRISVOID(b))
return new_intArrayType(0);
if (ARRISVOID(a))
@@ -130,6 +139,9 @@ inner_int_inter(ArrayType *a, ArrayType *b)
int i,
j;
+ CHECKARRVALID(a);
+ CHECKARRVALID(b);
+
if (ARRISVOID(a) || ARRISVOID(b))
return new_intArrayType(0);
@@ -243,7 +255,7 @@ copy_intArrayType(ArrayType *a)
ArrayType *r;
r = new_intArrayType(ARRNELEMS(a));
- memmove(r, a, VARSIZE(a));
+ memmove(r, a, VARSIZE(r));
return r;
}
@@ -270,6 +282,8 @@ _int_unique(ArrayType *r)
*data;
int num = ARRNELEMS(r);
+ CHECKARRVALID(r);
+
if (num < 2)
return r;
@@ -302,7 +316,10 @@ intarray_match_first(ArrayType *a, int32 elem)
c,
i;
- c = (ARRISVOID(a)) ? 0 : ARRNELEMS(a);
+ CHECKARRVALID(a);
+ if (ARRISVOID(a))
+ return 0;
+ c = ARRNELEMS(a);
aa = ARRPTR(a);
for (i = 0; i < c; i++)
if (aa[i] == elem)
@@ -315,8 +332,10 @@ intarray_add_elem(ArrayType *a, int32 elem)
{
ArrayType *result;
int32 *r;
- int32 c = (ARRISVOID(a)) ? 0 : ARRNELEMS(a);
+ int32 c;
+ CHECKARRVALID(a);
+ c = (ARRISVOID(a)) ? 0 : ARRNELEMS(a);
result = new_intArrayType(c + 1);
r = ARRPTR(result);
if (c > 0)
@@ -332,6 +351,8 @@ intarray_concat_arrays(ArrayType *a, ArrayType *b)
int32 ac = (ARRISVOID(a)) ? 0 : ARRNELEMS(a);
int32 bc = (ARRISVOID(b)) ? 0 : ARRNELEMS(b);
+ CHECKARRVALID(a);
+ CHECKARRVALID(b);
result = new_intArrayType(ac + bc);
if (ac)
memcpy(ARRPTR(result), ARRPTR(a), ac * sizeof(int32));