diff --git a/librz/core/cgraph.c b/librz/core/cgraph.c index 1f714316f7..3288ee8f82 100644 --- a/librz/core/cgraph.c +++ b/librz/core/cgraph.c @@ -993,12 +993,19 @@ static bool add_edge_to_cfg(RZ_NONNULL RzGraph /**/ *graph, return false; } - RzGraphNode *to_node = add_node_info_cfg(graph, op_to, false); + RzGraphNode *to_node = NULL; + bool found = false; + ut64 to_idx = ht_uu_find(nodes_visited, to, &found); + if (found) { + to_node = rz_graph_get_node(graph, to_idx); + } else { + to_node = add_node_info_cfg(graph, op_to, false); + } if (!to_node) { RZ_LOG_ERROR("Could not add node at 0x%" PFMT64x "\n", to); return false; } - ut64 to_idx = to_node->idx; + to_idx = to_node->idx; if (from == to) { from_idx = to_idx; } diff --git a/test/integration/test_analysis_graph.c b/test/integration/test_analysis_graph.c index 4a92b2a56c..470f757d07 100644 --- a/test/integration/test_analysis_graph.c +++ b/test/integration/test_analysis_graph.c @@ -261,7 +261,7 @@ bool test_analysis_graph_cfg() { RzGraph *g = rz_core_graph_cfg(core, 0x117a); // main() mu_assert_notnull(g, "Graph was NULL"); - mu_assert_eq(g->n_nodes, 26, "data graph node count"); + mu_assert_eq(g->n_nodes, 24, "data graph node count"); mu_assert_eq(g->n_edges, 25, "data graph edge count"); // Testing the node content is a little annoying. The nodes @@ -291,7 +291,7 @@ bool test_analysis_graph_cfg() { mu_assert_eq(info->cfg.address, 0x11a7, "info address"); mu_assert_eq(info->cfg.call_address, UT64_MAX, "info call address"); - info = rz_graph_get_node_info_data(rz_graph_get_node(g, 24)->data); + info = rz_graph_get_node_info_data(rz_graph_get_node(g, 23)->data); mu_assert_eq(info->type, RZ_GRAPH_NODE_TYPE_CFG, "info type"); mu_assert_eq(info->subtype, RZ_GRAPH_NODE_SUBTYPE_CFG_CALL, "info subtype"); mu_assert_eq(info->cfg.address, 0x11cd, "info address");