summaryrefslogtreecommitdiffstats
path: root/pacemaker/rewrite_snprintf.alter.cocci
blob: c68362417d4ff73b5f9c66b611b668b5530d576e (plain)
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
// Switch certain class of snprintf to use internal macro crm_snprintf_max
// jpokorny@redhat.com

@ has_crm_internal @
@@

#include <crm_internal.h>


@ snprintf_rewrite @
identifier fn;
identifier id_str;
identifier id_max;
identifier id_offset;
@@
fn(...) {
<...
id_offset +=
- snprintf(id_str + id_offset, id_max - id_offset
+ crm_snprintf_offset(id_str, id_offset, id_max
, ...);
...>
}


@ snprintf_assert depends on snprintf_rewrite forall @
identifier snprintf_rewrite.fn;
identifier snprintf_rewrite.id_max;
identifier snprintf_rewrite.id_offset;
@@
fn(...) {
<...
- CRM_LOG_ASSERT(id_offset > 0);
+ CRM_LOG_ASSERT(id_offset > 0 && id_offset < id_max);
...>
}


// this is not the best placement, it serves a subsequent manual review
// to denote necessity to add the include at all, and the reviewer will
// (hopefully) move the include to the correct location
@ snprintf_include depends on (snprintf_rewrite && !(has_crm_internal)) exists @
identifier snprintf_rewrite.fn;
@@
+ #include <crm_internal.h>  /* crm_snprintf_offset */

fn(...) { ... }


@ snprintf_make_const depends on snprintf_rewrite forall @
identifier snprintf_rewrite.fn;
identifier snprintf_rewrite.id_max;
identifier snprintf_rewrite.id_offset;
type t_max;
expression E_max;
@@
fn(...) {
<+...
- static t_max id_max = E_max;
+ static const t_max id_max = E_max;
...+>
}