Commit | Line | Data |
---|---|---|
3a314143 C |
1 | // run with the options -no_show_diff and -dir {directory} |
2 | ||
3 | virtual after_start | |
4 | ||
5 | @initialize:ocaml@ | |
6 | ||
7 | let tbl = Hashtbl.create(100) | |
8 | ||
9 | let add_if_not_present from f file = | |
10 | try let _ = Hashtbl.find tbl (f,file) in () | |
11 | with Not_found -> | |
12 | Hashtbl.add tbl (f,file) file; | |
13 | let it = new iteration() in | |
14 | (match file with | |
15 | Some fl -> it#set_files [fl] | |
16 | | None -> ()); | |
17 | it#add_virtual_rule After_start; | |
18 | it#add_virtual_identifier Err_ptr_function f; | |
19 | it#register() | |
20 | ||
21 | @r depends on !after_start exists@ | |
22 | identifier fn; | |
23 | position p; | |
24 | @@ | |
25 | ||
26 | fn@p(...) { <+... return (ERR_PTR(...)); ...+> } | |
27 | ||
28 | @statfns@ | |
29 | identifier r.fn; | |
30 | position r.p; | |
31 | @@ | |
32 | ||
33 | static fn@p(...) { ... } | |
34 | ||
35 | @script:ocaml depends on statfns@ | |
36 | fn << r.fn; | |
37 | p << r.p; | |
38 | @@ | |
39 | ||
40 | add_if_not_present "ERR_PTR" fn (Some ((List.hd p).file)) | |
41 | ||
42 | @script:ocaml depends on !statfns@ | |
43 | fn << r.fn; | |
44 | p << r.p; | |
45 | @@ | |
46 | ||
47 | add_if_not_present "ERR_PTR" fn None | |
48 | ||
49 | // ----------------------------------------------------------------------- | |
50 | // iterate | |
51 | ||
52 | @s depends on after_start exists@ | |
53 | identifier virtual.err_ptr_function, fn; | |
54 | position p; | |
55 | @@ | |
56 | ||
57 | fn@p(...) { <+... return err_ptr_function(...); ...+> } | |
58 | ||
59 | @statfns_call@ | |
60 | identifier s.fn; | |
61 | position s.p; | |
62 | @@ | |
63 | ||
64 | static fn@p(...) { ... } | |
65 | ||
66 | @script:ocaml depends on statfns_call@ | |
67 | fn << s.fn; | |
68 | p << s.p; | |
69 | err_ptr_function << virtual.err_ptr_function; | |
70 | @@ | |
71 | ||
72 | add_if_not_present err_ptr_function fn (Some ((List.hd p).file)) | |
73 | ||
74 | @script:ocaml depends on !statfns_call@ | |
75 | fn << s.fn; | |
76 | p << s.p; | |
77 | err_ptr_function << virtual.err_ptr_function; | |
78 | @@ | |
79 | ||
80 | add_if_not_present err_ptr_function fn None | |
81 | ||
82 | // ----------------------------------------------------------------------- | |
83 | // find bugs | |
84 | ||
85 | @e depends on after_start exists@ | |
86 | identifier virtual.err_ptr_function; | |
87 | expression x; | |
88 | identifier fld; | |
89 | position p1,p2; | |
90 | @@ | |
91 | ||
92 | ( | |
93 | IS_ERR(x = err_ptr_function(...)) | |
94 | | | |
95 | x@p1 = err_ptr_function(...) | |
96 | ) | |
97 | ... when != IS_ERR(x) | |
98 | ( | |
99 | (IS_ERR(x) ||...) | |
100 | | | |
101 | x@p2->fld | |
102 | ) | |
103 | ||
104 | @script:python@ | |
105 | p1 << e.p1; | |
106 | p2 << e.p2; | |
107 | @@ | |
108 | ||
109 | cocci.print_main("def",p1) | |
110 | cocci.print_secs("ref",p2) |