From 3df8df47215da8bfcec3a3d1fd1785138911b402 Mon Sep 17 00:00:00 2001 From: erg Date: Wed, 9 Feb 2011 23:01:28 +0000 Subject: [PATCH] Protect against an empty graph --- lib/twopigen/twopiinit.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/twopigen/twopiinit.c b/lib/twopigen/twopiinit.c index eb85b86a3..eced54419 100644 --- a/lib/twopigen/twopiinit.c +++ b/lib/twopigen/twopiinit.c @@ -36,9 +36,11 @@ static void twopi_init_node_edge(graph_t * g) node_t *n; edge_t *e; int i = 0; - rdata* alg = N_NEW(agnnodes(g), rdata); + int n_nodes = agnnodes(g); + rdata* alg; - GD_neato_nlist(g) = N_NEW(agnnodes(g) + 1, node_t *); + alg = N_NEW(n_nodes, rdata); + GD_neato_nlist(g) = N_NEW(n_nodes + 1, node_t *); for (n = agfstnode(g); n; n = agnxtnode(g, n)) { neato_init_node(n); ND_alg(n) = alg + i; @@ -67,6 +69,8 @@ void twopi_layout(Agraph_t * g) char *s; int setRoot = 0; + if (agnnodes(g) == 0) return; + twopi_init_graph(g); s = agget(g, "root"); if ((s = agget(g, "root"))) { @@ -147,6 +151,7 @@ void twopi_cleanup(graph_t * g) edge_t *e; n = agfstnode (g); + if (!n) return; /* empty graph */ free (ND_alg(n)); for (; n; n = agnxtnode(g, n)) { for (e = agfstout(g, n); e; e = agnxtout(g, e)) { -- 2.40.0