Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #10719 line graph not correctly #10721

Merged
merged 1 commit into from Jul 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would probably slow down graphs a bit, but correctness is more important

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets keep optimization for later then

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