Prevent creation of node duplicates. (#4233)
Because list-based graph implementation cannot differentiate nodes by their data, node duplicates are added, if we don't take care of it.
This commit is contained in:
parent
0867fd9d3d
commit
7558233da1
2 changed files with 11 additions and 4 deletions
|
|
@ -993,12 +993,19 @@ static bool add_edge_to_cfg(RZ_NONNULL RzGraph /*<RzGraphNodeInfo *>*/ *graph,
|
||||||
return false;
|
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) {
|
if (!to_node) {
|
||||||
RZ_LOG_ERROR("Could not add node at 0x%" PFMT64x "\n", to);
|
RZ_LOG_ERROR("Could not add node at 0x%" PFMT64x "\n", to);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ut64 to_idx = to_node->idx;
|
to_idx = to_node->idx;
|
||||||
if (from == to) {
|
if (from == to) {
|
||||||
from_idx = to_idx;
|
from_idx = to_idx;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -261,7 +261,7 @@ bool test_analysis_graph_cfg() {
|
||||||
|
|
||||||
RzGraph *g = rz_core_graph_cfg(core, 0x117a); // main()
|
RzGraph *g = rz_core_graph_cfg(core, 0x117a); // main()
|
||||||
mu_assert_notnull(g, "Graph was NULL");
|
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");
|
mu_assert_eq(g->n_edges, 25, "data graph edge count");
|
||||||
|
|
||||||
// Testing the node content is a little annoying. The nodes
|
// 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.address, 0x11a7, "info address");
|
||||||
mu_assert_eq(info->cfg.call_address, UT64_MAX, "info call 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->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->subtype, RZ_GRAPH_NODE_SUBTYPE_CFG_CALL, "info subtype");
|
||||||
mu_assert_eq(info->cfg.address, 0x11cd, "info address");
|
mu_assert_eq(info->cfg.address, 0x11cd, "info address");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue