From: Donald Caldwell Date: Sun, 8 Jan 2012 04:15:01 +0000 (-0500) Subject: RectArea versions for systems with or w/o long long X-Git-Tag: LAST_LIBGRAPH~32^2~584 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=de8daea11c68f19db18be44cd28149e2fd8d9548;p=graphviz RectArea versions for systems with or w/o long long AC_CHECK_SIZEOF macros added to configure.ac --- diff --git a/configure.ac b/configure.ac index acbd2dee7..a1d654b49 100644 --- a/configure.ac +++ b/configure.ac @@ -3205,6 +3205,9 @@ else fi rm -f conftest* +# ----------------------------------------------------------------------- +AC_CHECK_SIZEOF([long long]) +AC_CHECK_SIZEOF([int]) # ----------------------------------------------------------------------- # Generate Makefiles diff --git a/lib/label/rectangle.c b/lib/label/rectangle.c index 94b06cc6a..4364c99e6 100644 --- a/lib/label/rectangle.c +++ b/lib/label/rectangle.c @@ -116,6 +116,9 @@ void PrintRect(Rect_t * r) /*----------------------------------------------------------------------------- | Calculate the n-dimensional area of a rectangle -----------------------------------------------------------------------------*/ +void agerror(char *); + +#if SIZEOF_LONG_LONG > SIZEOF_INT unsigned int RectArea(Rect_t * r) { register int i; @@ -130,19 +133,55 @@ unsigned int RectArea(Rect_t * r) */ area = 1; for (i = 0; i < NUMDIMS; 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; + } + return area; +} #else - area *= r->boundary[i + NUMDIMS] - r->boundary[i]; -#endif +unsigned int RectArea(Rect_t * r) +{ + register int i; + unsigned int area=1, a=1; + assert(r); + + if (Undefined(r)) return 0; + + /* + * XXX add overflow checks + */ + area = 1; + for (i = 0; i < NUMDIMS; i++) { + unsigned int b = r->boundary[i + NUMDIMS] - r->boundary[i]; + a *= b; + if( (a / b ) != area) { + agerror("label: area too large for rtree\n"); + return UINT_MAX; + } + area = a; + } + return area; +} +#endif /*SIZEOF_LONG_LONG > SIZEOF_INT*/ +#if 0 /*original code*/ +int RectArea(Rect_t * r) +{ + register int i, area=1; + assert(r); + + if (Undefined(r)) + return 0; + area = 1; + for (i = 0; i < NUMDIMS; i++) { + area *= r->boundary[i + NUMDIMS] - r->boundary[i]; } return area; } +#endif /*----------------------------------------------------------------------------- | Combine two rectangles, make one that includes both.