]> granicus.if.org Git - graphviz/commitdiff
exit when rectangle area computation overflows
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 19 Jun 2022 21:42:07 +0000 (14:42 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 25 Jun 2022 03:04:35 +0000 (20:04 -0700)
Continuing in the face of an overflow when calculating rectangle area was sort
of pointless. The test case for #1906 is an example of this, that runs for many
minutes _repeatedly_ detecting overflows in this code before finally erroring
out when trying to do follow on layout with values that make no sense. It is
simpler and cheaper to just error out immediately when this happens.

Gitlab: #1906

lib/label/rectangle.c

index d8c35c48249f0f4f0ae6fa6f4c1ff11a80942986..952eaa959b1522df8bd6af3ed90aee2e97184a41 100644 (file)
 #include "config.h"
 
 #include <label/index.h>
-#include <stddef.h>
 #include <stdio.h>
 #include <assert.h>
 #include <limits.h>
+#include <stdlib.h>
 #include <common/logic.h>
 #include <common/arith.h>
 #include <label/rectangle.h>
 #include <cgraph/cgraph.h>
+#include <cgraph/exit.h>
 
 #define Undefined(x) ((x)->boundary[0] > (x)->boundary[NUMDIMS])
 
@@ -75,7 +76,7 @@ unsigned int RectArea(Rect_t * r)
       if (dim == 0) return 0;
       if (UINT_MAX / dim < area) {
        agerr (AGERR, "label: area too large for rtree\n");
-       return UINT_MAX;
+       graphviz_exit(EXIT_FAILURE);
       }
       area *= dim;
     }