Changeset: 78588a6331f5 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=78588a6331f5 Modified Files: monetdb5/modules/mal/array.mx Branch: SciQL-2 Log Message:
ARRAYslice(): use correct types: With pci->argc & pci->retc being of type int, there is no point in having variables valence, i, & j of type BUN; use type int instead. Also added some assertions when (possibly) down-casting from lng to BUN or from lng to oid. diffs (68 lines): diff --git a/monetdb5/modules/mal/array.mx b/monetdb5/modules/mal/array.mx --- a/monetdb5/modules/mal/array.mx +++ b/monetdb5/modules/mal/array.mx @@ -351,8 +351,8 @@ ARRAYslice(Client cntxt, MalBlkPtr mb, M int *ret = (int*) getArgReference(stk,pci,0); lng *dim_strt = NULL, *dim_step = NULL, *dim_stop = NULL, *dim_size = NULL, *dim_rept = NULL, *slc_strt = NULL, *slc_step = NULL, *slc_stop = NULL, *slc_size = NULL, *slc_rept = NULL, *slc_indx = NULL; - BUN i = 0, j = 0; - BUN rescnt = 1, valence = (pci->argc - pci->retc) / 6; + int i = 0, j = 0, valence = (pci->argc - pci->retc) / 6; + BUN k = 0, rescnt = 1; BAT *res = NULL; oid *resT = NULL; @@ -396,24 +396,25 @@ ARRAYslice(Client cntxt, MalBlkPtr mb, M slc_rept[i] = 1; slc_indx[i] = 0; - rescnt *= slc_size[i]; + assert(slc_size[i] <= (lng) (BUN_MAX / rescnt)); + rescnt *= (BUN) slc_size[i]; if ( (slc_step[i] > 0 && (slc_strt[i] < dim_strt[i] || slc_stop[i] > dim_stop[i])) || (slc_step[i] < 0 && (slc_strt[i] > dim_strt[i] || slc_stop[i] < dim_stop[i])) ) { SLICE_CLEANUP(); - throw(MAL, "array.slice", "Slice range [%lld:%lld:%lld] of the " BUNFMT "-th dimension out of bound ([%lld:%lld:%lld])", + throw(MAL, "array.slice", "Slice range [%lld:%lld:%lld] of the %d-th dimension out of bound ([%lld:%lld:%lld])", slc_strt[i], slc_step[i], slc_stop[i], i, dim_strt[i], dim_step[i], dim_stop[i]); } if ((slc_strt[i] - dim_strt[i]) % dim_step[i] != 0) { SLICE_CLEANUP(); - throw(MAL, "array.slice", "Invalid slice range of the " BUNFMT "-th dimension: the slicing start value '%lld' is not a valid value of this dimension", + throw(MAL, "array.slice", "Invalid slice range of the %d-th dimension: the slicing start value '%lld' is not a valid value of this dimension", i, slc_strt[i]); } if ((slc_strt[i] - dim_strt[i]) % dim_step[i] != 0) { SLICE_CLEANUP(); - throw(MAL, "array.slice", "Invalid slice range of the " BUNFMT "-th dimension: the slicing step size '%lld' is not a multiple of the step size '%lld' of this dimension", + throw(MAL, "array.slice", "Invalid slice range of the %d-th dimension: the slicing step size '%lld' is not a multiple of the step size '%lld' of this dimension", i, slc_step[i], dim_step[i]); } } @@ -435,17 +436,19 @@ ARRAYslice(Client cntxt, MalBlkPtr mb, M resT = (oid *) Tloc(res, BUNfirst(res)); /* the main loop: compute the index of each cell selected by the slicing */ - for (i = 0; i < rescnt; i++) { - resT[i] = 0; + for (k = 0; k < rescnt; k++) { + resT[k] = 0; /* compute the formula for each dimension, then sum them up to get the index */ for (j = 0; j < valence; j++) { - resT[i] += (slc_strt[j] + slc_indx[j] * slc_step[j] - dim_strt[j]) / dim_step[j] * dim_rept[j]; + lng inc = (slc_strt[j] + slc_indx[j] * slc_step[j] - dim_strt[j]) / dim_step[j] * dim_rept[j]; + assert(inc <= (lng) (GDK_oid_max - resT[k])); + resT[k] += (oid) inc; /* only increase the index into the slicing elements if the current * element has been repeated slc_rept[j] times. * reset the index into the slicing elements if all elements have * already been processed once. */ - slc_indx[j] = (((i + 1) % slc_rept[j]) == 0)? ((slc_indx[j] + 1) % slc_size[j]) : slc_indx[j]; + slc_indx[j] = (((k + 1) % slc_rept[j]) == 0)? ((slc_indx[j] + 1) % slc_size[j]) : slc_indx[j]; } } _______________________________________________ checkin-list mailing list checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list