Coccinelle release-1.0.0-rc11
[bpt/coccinelle.git] / engine / c_vs_c.ml
index a38b037..e82e717 100644 (file)
@@ -1,5 +1,7 @@
 (*
- * Copyright 2010, INRIA, University of Copenhagen
+ * Copyright 2012, INRIA
+ * Julia Lawall, Gilles Muller
+ * Copyright 2010-2011, INRIA, University of Copenhagen
  * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
  * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
  * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
@@ -218,7 +220,9 @@ and typeC tya tyb =
   | StructUnion (sua, saopt, sta), StructUnion (sub, sbopt, stb) ->
       (sua =*= sub && saopt =*= sbopt && List.length sta =|= List.length stb)
       >&&>
-      Common.zip sta stb +> List.fold_left
+      (function tin ->
+       (* zip is only safe if the above succeeds *)
+      (Common.zip sta stb +> List.fold_left
         (fun acc ((fielda), (fieldb)) ->
           acc >>= (fun xs ->
             match fielda, fieldb with
@@ -230,8 +234,9 @@ and typeC tya tyb =
               DeclarationField (FieldDeclList (fb, iiptb)) ->
                 let iipt = iipta in (* TODO ?*)
                 (List.length fa =|= List.length fb) >&&>
-
-                Common.zip fa fb +> List.fold_left
+               (function tin ->
+                 (* only executable if the length is correct *)
+                (Common.zip fa fb +> List.fold_left
                   (fun acc2 ((fielda,iia),(fieldb,iib))->
                     let iix = iia in
                     acc2 >>= (fun xs ->
@@ -253,7 +258,7 @@ and typeC tya tyb =
                           )
                       | _,_ -> fail
                     )
-                  ) (return [])
+                  ) (return [])) tin)
                  >>= (fun fx ->
                    return (((DeclarationField
                                (FieldDeclList (List.rev fx,iipt))))::xs)
@@ -265,7 +270,7 @@ and typeC tya tyb =
         ) (return [])
         >>= (fun stx ->
           return (StructUnion (sua, saopt, List.rev stx), iix)
-        )
+        )) tin)