summaryrefslogtreecommitdiff
path: root/src/ipcpd/normal/graph.c
diff options
context:
space:
mode:
authorSander Vrijders <[email protected]>2017-03-24 10:28:55 +0000
committerdimitri staessens <[email protected]>2017-03-24 10:28:55 +0000
commit7c5727c35c961c0b579a754ecdf0870b8db383b1 (patch)
tree2b136e527a744f5f2a818711728e0ce97fdd6b78 /src/ipcpd/normal/graph.c
parent6688251a7a18f267535c5369c1e856d2c2c1605e (diff)
parent81a70d5ed630cad01b5a47a56b96c4d7bfe08765 (diff)
downloadouroboros-7c5727c35c961c0b579a754ecdf0870b8db383b1.tar.gz
ouroboros-7c5727c35c961c0b579a754ecdf0870b8db383b1.zip
Merged in sandervrijders/ouroboros/be-segv (pull request #418)
ipcpd: normal: Fix segfault in dijkstra calculation
Diffstat (limited to 'src/ipcpd/normal/graph.c')
-rw-r--r--src/ipcpd/normal/graph.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/ipcpd/normal/graph.c b/src/ipcpd/normal/graph.c
index 2ae36918..ecaff14c 100644
--- a/src/ipcpd/normal/graph.c
+++ b/src/ipcpd/normal/graph.c
@@ -340,7 +340,8 @@ static int get_min_vertex(struct vertex ** vertices,
}
}
- vertices[index] = NULL;
+ if (index != -1)
+ vertices[index] = NULL;
return index;
}
@@ -395,6 +396,7 @@ static struct vertex ** dijkstra(struct graph * graph,
if (prev == NULL)
return NULL;
+ /* Init the data structures */
list_for_each(p, &graph->vertices) {
v = list_entry(p, struct vertex, next);
vertices[i] = v;
@@ -406,6 +408,7 @@ static struct vertex ** dijkstra(struct graph * graph,
i++;
}
+ /* Perform actual Dijkstra */
i = get_min_vertex(vertices, graph->nr_vertices, dist, &v);
while (v != NULL) {
list_for_each(p, &v->edges) {
@@ -428,6 +431,7 @@ static struct vertex ** dijkstra(struct graph * graph,
prev[j] = v;
}
}
+ i = get_min_vertex(vertices, graph->nr_vertices, dist, &v);
}
return prev;
@@ -462,6 +466,10 @@ ssize_t graph_routing_table(struct graph * graph,
return -1;
}
+ /*
+ * Now loop through the list of predecessors
+ * to construct the routing table
+ */
list_for_each(p, &graph->vertices) {
v = list_entry(p, struct vertex, next);
prev = prevs[i];