Skip to content

Commit

Permalink
Switched to alternative way of deleting dup edges
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanpencil authored and XVilka committed Jul 13, 2018
1 parent d3a3940 commit fdd4b30
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
18 changes: 18 additions & 0 deletions libr/core/graph.c
Expand Up @@ -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;
Expand Down Expand Up @@ -2207,6 +2224,7 @@ static int get_bbnodes(RAGraph *g, RCore *core, RAnalFunction *fcn) {
}
}

delete_dup_edges (g);
ret = true;

cleanup:
Expand Down
12 changes: 5 additions & 7 deletions libr/util/graph.c
Expand Up @@ -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++;
}
}

Expand Down

0 comments on commit fdd4b30

Please sign in to comment.