UBSan revealed the graph attached to #1999 was triggering an integer overflow in
this multiplication, later on causing a crash in `twopi`. Any number of nodes
≥⌈√INT_MAX⌉ exceeds INT_MAX during multiplication. This fix still does not
enable the graph to be processed in a reasonable amount of time, and it still
crashes later after several hours due to another integer overflow.
Gitlab: #1999
* Contributors: Details at https://graphviz.org
*************************************************************************/
+#include <assert.h>
#include <cgraph/alloc.h>
#include <twopigen/circle.h>
#include <ctype.h>
static void initLayout(Agraph_t * g)
{
int nnodes = agnnodes(g);
- uint64_t INF = (uint64_t)(nnodes * nnodes);
+ assert(nnodes >= 0);
+ uint64_t INF = (uint64_t)nnodes * (uint64_t)nnodes;
for (Agnode_t *n = agfstnode(g); n; n = agnxtnode(g, n)) {
SCENTER(n) = INF;