From 8ede2fd32c69b174073b23838bcb7c812285ad0d Mon Sep 17 00:00:00 2001 From: Jeffrey Crowell Date: Fri, 8 Jan 2016 13:42:41 -0500 Subject: [PATCH] fix infinite loop in graph minimize_crossings see https://github.com/praetorian-inc/angr/tree/binaries/tests/binaries/tests/x86_64 for test binary --- libr/core/graph.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libr/core/graph.c b/libr/core/graph.c index 975116a94d..ceae9b7101 100644 --- a/libr/core/graph.c +++ b/libr/core/graph.c @@ -567,21 +567,25 @@ static void create_layers (RAGraph *g) { /* it permutes each layer, trying to find the best ordering for each layer * to minimize the number of crossing edges */ static void minimize_crossings (const RAGraph *g) { - int i, cross_changed; + int i, cross_changed, max_changes = 4096; do { cross_changed = false; + --max_changes; for (i = 0; i < g->n_layers; ++i) cross_changed |= layer_sweep (g->graph, g->layers, g->n_layers, i, true); - } while (cross_changed); + } while (cross_changed && max_changes); + + max_changes = 4096; do { cross_changed = false; + --max_changes; for (i = g->n_layers - 1; i >= 0; --i) cross_changed |= layer_sweep (g->graph, g->layers, g->n_layers, i, false); - } while (cross_changed); + } while (cross_changed && max_changes); } static int find_dist (const struct dist_t *a, const struct dist_t *b) {