for ( d = 0; d < ndims; d++ )
{
/* Initialize counts for this dimension */
- memset(counts, 0, sizeof(int)*NUM_BINS);
+ memset(counts, 0, sizeof(counts));
smin = extent->min[d];
smax = extent->max[d];
}
/* What bins does this range correspond to? */
- bmin = NUM_BINS * (minoffset) / swidth;
- bmax = NUM_BINS * (maxoffset) / swidth;
+ bmin = floor(NUM_BINS * minoffset / swidth);
+ bmax = floor(NUM_BINS * maxoffset / swidth);
+
+ /* Should only happen when maxoffset==swidth */
+ if (bmax >= NUM_BINS)
+ bmax = NUM_BINS-1;
POSTGIS_DEBUGF(4, " dimension %d, feature %d: bin %d to bin %d", d, i, bmin, bmax);