#include "index.h"
#include <stdio.h>
#include <assert.h>
+#include <limits.h>
#include "logic.h"
#include "arith.h"
#include "rectangle.h"
/*-----------------------------------------------------------------------------
| Calculate the n-dimensional area of a rectangle
-----------------------------------------------------------------------------*/
-int RectArea(Rect_t * r)
+unsigned int RectArea(Rect_t * r)
{
- register int i, area;
- assert(r);
+ register int i;
+ unsigned int area;
+ assert(r);
if (Undefined(r))
return 0;
+ /*
+ * XXX add overflow checks
+ */
area = 1;
for (i = 0; i < NUMDIMS; i++) {
- area *= r->boundary[i + NUMDIMS] - r->boundary[i];
+#if 1 /* overflow check */
+ long long a_test = area * r->boundary[i + NUMDIMS] - r->boundary[i];
+ if( a_test > UINT_MAX) {
+ agerror("label: area too large for rtree\n");
+ return UINT_MAX;
+ }
+ area = a_test;
+#else
+ area *= r->boundary[i + NUMDIMS] - r->boundary[i];
+#endif
}
return area;
}
#ifdef RTDEBUG
void PrintRect(Rect_t *);
#endif
-int RectArea(Rect_t *);
+unsigned int RectArea(Rect_t *);
int Overlap(Rect_t *, Rect_t *);
int Contained(Rect_t *, Rect_t *);
Rect_t CombineRect(Rect_t *, Rect_t *);
-----------------------------------------------------------------------------*/
static void PickSeeds(RTree_t * rtp)
{
- register int i, j, waste, worst, seed0, seed1;
- int area[NODECARD + 1];
+ register int i, j;
+ unsigned int waste, worst;
+ int seed0, seed1;
+ unsigned int area[NODECARD + 1];
for (i = 0; i < NODECARD + 1; i++)
area[i] = RectArea(&rtp->split.BranchBuf[i].rect);
- worst = -rtp->split.CoverSplitArea - 1;
+ //worst = -rtp->split.CoverSplitArea - 1;
+ worst=0;
for (i = 0; i < NODECARD; i++) {
for (j = i + 1; j < NODECARD + 1; j++) {
Rect_t rect;
typedef struct split_q_s {
struct Branch BranchBuf[NODECARD + 1];
struct Rect CoverSplit;
- int CoverSplitArea;
+ unsigned int CoverSplitArea;
struct PartitionVars Partitions[METHODS];
} SplitQ_t;