Blame view

RIOT/dist/tools/coccinelle/warn/notnull.cocci 1.56 KB
a752c7ab   elopes   add first test an...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
  // this detects NULL tests that can only be reached when the value is known
  // not to be NULL
  //
  // Confidence: High
  // Copyright: (C) Gilles Muller, Julia Lawall, EMN, INRIA, DIKU.  GPLv2.
  // URL: http://coccinelle.lip6.fr/rules/notnull.html
  // Options:
  
  @r exists@
  local idexpression x;
  expression E;
  position p1,p2;
  @@
  
  if (x@p1 == NULL || ...) { ... when forall
     return ...; }
  ... when != \(x=E\|x--\|x++\|--x\|++x\|x-=E\|x+=E\|x|=E\|x&=E\)
      when != &x
  (
  x@p2 == NULL
  |
  x@p2 != NULL
  )
  
  // another path to the test that is not through p1?
  
  @s exists@
  local idexpression r.x;
  position r.p1,r.p2;
  @@
  
  ... when != x@p1
  (
  x@p2 == NULL
  |
  x@p2 != NULL
  )
  
  // another path to the test from p1?
  
  @t exists@
  local idexpression x;
  position r.p1,r.p2;
  @@
  
  if (x@p1 == NULL || ...) { ... x@p2 ... when any
     return ...; }
  
  // another path to the test containing an assignment?
  
  @u exists@
  local idexpression x;
  expression E;
  position r.p1,r.p2;
  @@
  
  if (x@p1 == NULL || ...) { ... when forall
     return ...; }
   ...
   \(x=E\|x--\|x++\|--x\|++x\|x-=E\|x+=E\|x|=E\|x&=E\|&x\)
   ...  when != x@p1
        when any
  (
  x@p2 == NULL
  |
  x@p2 != NULL
  )
  
  @fix depends on !s && !t && !u@
  position r.p2;
  expression x,E;
  statement S1,S2;
  @@
  
  (
  - if ((x@p2 != NULL) || ...)
    S1
  |
  - if ((x@p2 != NULL) || ...)
    S1
  - else S2
  |
  - (x@p2 != NULL) && E
  + E
  |
  - (x@p2 == NULL) || E
  + E
  |
  - if ((x@p2 == NULL) && ...) S1
  |
  - if ((x@p2 == NULL) && ...) S1 else
    S2
  |
  - BUG_ON(x@p2 == NULL);
  )
  
  @script:python depends on !s && !t && !u && !fix@
  p1 << r.p1;
  p2 << r.p2;
  @@
  
  cocci.print_main("",p1)
  cocci.print_secs("retest",p2)