Fix segfault in RGraph.domTree()

This commit is contained in:
pancake 2023-06-30 03:38:28 +02:00
parent af592f8ce2
commit 7d414d1844
3 changed files with 20 additions and 4 deletions

View File

@ -4339,6 +4339,7 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int
} else {
o_can = g->can;
}
g->can = can;
g->movspeed = r_config_get_i (core->config, "graph.scroll");
const int graph_zoom = r_config_get_i (core->config, "graph.zoom");
@ -4390,6 +4391,21 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int
core->cons->event_resize = (RConsEvent) agraph_refresh_oneshot;
r_cons_break_push (NULL, NULL);
#if 0
// XXX wrong usage or buggy RGraph.domTree()
// dominance tree here
const RList *l = r_graph_get_nodes (g->graph);
RGraphNode *root = r_list_first (l);
if (root) {
RGraph *dg = r_graph_dom_tree (g->graph, root);
if (dg) {
g->graph = dg;
} else {
R_LOG_WARN ("Cannot compute the dominance tree");
sleep (1);
}
}
#endif
while (!exit_graph && !is_error && !r_cons_is_breaked ()) {
w = r_cons_get_size (&h);

View File

@ -10860,7 +10860,7 @@ static void r_core_graph_print(RCore *core, RGraph /*<RGraphNodeInfo>*/ *graph,
RGraphNode *graphNode, *target;
RGraphNodeInfo *print_node;
if (use_utf != -1) {
r_config_set_i (core->config, "scr.utf8", use_utf);
r_config_set_b (core->config, "scr.utf8", use_utf);
}
switch (*input) {
case 0:

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2007-2020 - pancake, ret2libc */
/* radare - LGPL - Copyright 2007-2023 - pancake, ret2libc, condret */
#include <r_util.h>
@ -392,7 +392,7 @@ R_API RGraph *r_graph_dom_tree(RGraph *graph, RGraphNode *root) {
while (r_list_length (di.mi)) {
RGraphNode *n = r_list_pop (di.mi);
RGraphNode *p = (RGraphNode *)r_list_get_n (n->in_nodes, 0);
if (((RGraphDomNode *)(p->data))->idx == 0) {
if (p && ((RGraphDomNode *)(p->data))->idx == 0) {
//parent is root node
continue;
}
@ -411,7 +411,7 @@ R_API RGraph *r_graph_dom_tree(RGraph *graph, RGraphNode *root) {
max_n = in;
}
}
while (((RGraphDomNode *)max_n->data)->idx > dn->idx) {
while (max_n && ((RGraphDomNode *)max_n->data)->idx > dn->idx) {
max_n = (RGraphNode *)r_list_get_n (max_n->in_nodes, 0);
}
r_graph_del_edge (g, p, n);