From 089091d59be302979d116cd557c71f65f5aa91db Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Sat, 10 Nov 2007 23:18:01 +0000 Subject: [PATCH] Added a safety check when building the flow graph --- common/FlowGraph.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/common/FlowGraph.hs b/common/FlowGraph.hs index 9486bd2..7e2002e 100644 --- a/common/FlowGraph.hs +++ b/common/FlowGraph.hs @@ -127,7 +127,11 @@ buildFlowGraph funcs s addEdge :: EdgeLabel -> Node -> Node -> GraphMaker mLabel mAlter label () addEdge label start end = do (n, pi, (nodes, edges)) <- get - put (n + 1, pi, (nodes,(start, end, label):edges)) + -- Edges should only be added after the nodes, so + -- for safety here we can check that the nodes exist: + if (notElem start $ map fst nodes) || (notElem end $ map fst nodes) + then throwError "Could not add edge between non-existent nodes" + else put (n + 1, pi, (nodes,(start, end, label):edges)) addNode' :: Meta -> (GraphLabelFuncs mLabel label -> (b -> mLabel label)) -> b -> AlterAST mAlter -> GraphMaker mLabel mAlter label Node addNode' m f t r = do val <- (lift . lift) (run f t)