// // open.cocci (based on kmalloc 7) // // @r exists@ local idexpression x; statement S; expression E; identifier f,l; position p1,p2,p3; expression *ptr != NULL; @@ ( if ((x@p1 = \(open\|fopen\)(...)) == NULL) S | x@p1 = \(open\|fopen\)(...); ... if (x == NULL) S ) <... when != x when != if (...) { <+...x...+> } ( goto@p3 l; | x->f = E ) ...> ( return \(0\|<+...x...+>\|ptr\); | return@p2 ...; ) @script:python@ p1 << r.p1; p2 << r.p2; @@ cocci.print_main("",p1) cocci.print_secs("", p2)