88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.76 2002/03/16 22:47:13 tgl Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.77 2002/03/20 19:41:47 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -907,10 +907,10 @@ array_get_slice(ArrayType *array,
907907 * with an empty slice, return NULL (should it be an empty array
908908 * instead?)
909909 */
910- if (ndim != nSubscripts || ndim <=0 || ndim > MAXDIM )
910+ if (ndim < nSubscripts || ndim <=0 || ndim > MAXDIM )
911911RETURN_NULL (ArrayType * );
912912
913- for (i = 0 ;i < ndim ;i ++ )
913+ for (i = 0 ;i < nSubscripts ;i ++ )
914914{
915915if (lowerIndx [i ]< lb [i ])
916916lowerIndx [i ]= lb [i ];
@@ -919,8 +919,16 @@ array_get_slice(ArrayType *array,
919919if (lowerIndx [i ]> upperIndx [i ])
920920RETURN_NULL (ArrayType * );
921921}
922+ /* fill any missing subscript positions with full array range */
923+ for (;i < ndim ;i ++ )
924+ {
925+ lowerIndx [i ]= lb [i ];
926+ upperIndx [i ]= dim [i ]+ lb [i ]- 1 ;
927+ if (lowerIndx [i ]> upperIndx [i ])
928+ RETURN_NULL (ArrayType * );
929+ }
922930
923- mda_get_range (nSubscripts ,span ,lowerIndx ,upperIndx );
931+ mda_get_range (ndim ,span ,lowerIndx ,upperIndx );
924932
925933bytes = array_slice_size (ndim ,dim ,lb ,arraydataptr ,
926934elmlen ,lowerIndx ,upperIndx );
@@ -1120,6 +1128,9 @@ array_set(ArrayType *array,
11201128 * A new array is returned, just like the old except for the
11211129 * modified range.
11221130 *
1131+ * NOTE: we assume it is OK to scribble on the provided index arrays
1132+ * lowerIndx[] and upperIndx[]. These are generally just temporaries.
1133+ *
11231134 * NOTE: For assignments, we throw an error for silly subscripts etc,
11241135 * rather than returning a NULL as the fetch operations do. The reasoning
11251136 * is that returning a NULL would cause the user's whole array to be replaced
@@ -1172,7 +1183,7 @@ array_set_slice(ArrayType *array,
11721183/* note: we assume srcArray contains no toasted elements */
11731184
11741185ndim = ARR_NDIM (array );
1175- if (ndim != nSubscripts || ndim <=0 || ndim > MAXDIM )
1186+ if (ndim < nSubscripts || ndim <=0 || ndim > MAXDIM )
11761187elog (ERROR ,"Invalid array subscripts" );
11771188
11781189/* copy dim/lb since we may modify them */
@@ -1185,7 +1196,7 @@ array_set_slice(ArrayType *array,
11851196 * extend the array as long as no hole is created. An empty slice is
11861197 * an error, too.
11871198 */
1188- for (i = 0 ;i < ndim ;i ++ )
1199+ for (i = 0 ;i < nSubscripts ;i ++ )
11891200{
11901201if (lowerIndx [i ]> upperIndx [i ])
11911202elog (ERROR ,"Invalid array subscripts" );
@@ -1207,6 +1218,14 @@ array_set_slice(ArrayType *array,
12071218elog (ERROR ,"Invalid array subscripts" );
12081219}
12091220}
1221+ /* fill any missing subscript positions with full array range */
1222+ for (;i < ndim ;i ++ )
1223+ {
1224+ lowerIndx [i ]= lb [i ];
1225+ upperIndx [i ]= dim [i ]+ lb [i ]- 1 ;
1226+ if (lowerIndx [i ]> upperIndx [i ])
1227+ elog (ERROR ,"Invalid array subscripts" );
1228+ }
12101229
12111230/*
12121231 * Make sure source array has enough entries. Note we ignore the