diff --git a/contrib/intarray/_int_tool.c b/contrib/intarray/_int_tool.c
index 79f018d..4d7a1f2 100644
--- a/contrib/intarray/_int_tool.c
+++ b/contrib/intarray/_int_tool.c
@@ -159,7 +159,7 @@ inner_int_inter(ArrayType *a, ArrayType *b)
 			i++;
 		else if (da[i] == db[j])
 		{
-			if (i + j == 0 || (i + j > 0 && *(dr - 1) != db[j]))
+			if (i + j == 0 || (i + j > 0 && (dr - ARRPTR(r)) == 0) || (i + j > 0 && *(dr - 1) != db[j]))
 				*dr++ = db[j];
 			i++;
 			j++;
