From 250a32990068bc1d59e0bc5bd0251f5d66b9c1d0 Mon Sep 17 00:00:00 2001 From: cyanpencil Date: Thu, 12 Jul 2018 22:56:40 +0200 Subject: [PATCH] Switched to alternative way of deleting dup edges --- libr/core/graph.c | 18 ++++++++++++++++++ libr/util/graph.c | 12 +++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/libr/core/graph.c b/libr/core/graph.c index e2f044fc8483a..149e196bcb33a 100644 --- a/libr/core/graph.c +++ b/libr/core/graph.c @@ -2125,6 +2125,23 @@ static void get_bbupdate(RAGraph *g, RCore *core, RAnalFunction *fcn) { core->anal->stackptr = saved_stackptr; } +static void delete_dup_edges (RAGraph *g) { + RListIter *iter, *in_iter, *in_iter2; + RGraphNode *n, *a, *b; + r_list_foreach (g->graph->nodes, iter, n) { + r_list_foreach (n->out_nodes, in_iter, a) { + r_list_foreach (n->out_nodes, in_iter2, b) { + if (in_iter == in_iter2) { + continue; + } + if (a->idx == b->idx) { + r_graph_del_edge (g->graph, n, b); + } + } + } + } +} + /* build the RGraph inside the RAGraph g, starting from the Basic Blocks */ static int get_bbnodes(RAGraph *g, RCore *core, RAnalFunction *fcn) { RAnalBlock *bb; @@ -2207,6 +2224,7 @@ static int get_bbnodes(RAGraph *g, RCore *core, RAnalFunction *fcn) { } } + delete_dup_edges (g); ret = true; cleanup: diff --git a/libr/util/graph.c b/libr/util/graph.c index a750515f88d4f..3de7b89db4bb9 100644 --- a/libr/util/graph.c +++ b/libr/util/graph.c @@ -182,13 +182,11 @@ R_API void r_graph_add_edge (RGraph *t, RGraphNode *from, RGraphNode *to) { R_API void r_graph_add_edge_at (RGraph *t, RGraphNode *from, RGraphNode *to, int nth) { if (from && to) { - if (!r_list_contains (from->out_nodes, to)) { - r_list_insert (from->out_nodes, nth, to); - r_list_append (from->all_neighbours, to); - r_list_append (to->in_nodes, from); - r_list_append (to->all_neighbours, from); - t->n_edges++; - } + r_list_insert (from->out_nodes, nth, to); + r_list_append (from->all_neighbours, to); + r_list_append (to->in_nodes, from); + r_list_append (to->all_neighbours, from); + t->n_edges++; } }