Skip to content

Commit

Permalink
fixes start and exit insertion for singleton graphs (#1060)
Browse files Browse the repository at this point in the history
In #1051 we begun inserting `start` and `exit` pseudonodes and
introduced a small bug, when the graph is singleton and has a node
with both indegree and outdegree equal to zero. For that graphs,
instead of
```
digraph {
start -> n -> exit
}
```
we got
```
digraph {
start -> n;
start -> exit;
}
```

since we didn't insert an edge from `n` to `exit`.
  • Loading branch information
ivg authored Feb 20, 2020
1 parent 55bc005 commit 2ad537a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/bap_types/bap_tid_graph.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@ let connect_with_start n =
G.Edge.insert @@
G.Edge.create start n start

let if_unreachable ~from connect g n =
if G.Node.degree ~dir:from n g = 0
then connect n
else ident

let create sub =
let g = of_sub sub in
G.nodes g |> Seq.fold ~init:g ~f:(fun g n ->
if G.Node.degree ~dir:`Out n g = 0
then connect_with_exit n g else
if G.Node.degree ~dir:`In n g = 0
then connect_with_start n g
else g) |> fun g ->
g |>
if_unreachable ~from:`In connect_with_start g n |>
if_unreachable ~from:`Out connect_with_exit g n) |> fun g ->
Graphlib.depth_first_search (module G) g
~init:g ~start
~start_tree:connect_with_start
Expand Down

0 comments on commit 2ad537a

Please sign in to comment.