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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
extern void pf1(char *msg, ...) __attribute__((format (printf, 1, 2)));
extern void pf2(int m, char *msg, ...) __attribute__((format (printf, 2, 3)));
/* run all the tests with both of these printf formatted types */
#define pf(x...) do { pf1(x); pf2(1, x); } while(0);
static void test(void) {
/* first two are valid */
pf("%*d", 5, 10); /* value 10, print width is 5 */
pf("%2$*1$d", 5, 10); /* value 10, print width is 5 */
pf("%2$*3$d", 5, 10); /* value 10, print width is ?? */
pf("%*d", 5, 10); /* value 10, print width is 5 */
pf("%*d", 5, 10L); /* value 10, print width is 5 (bad type) */
pf("%*d", 5UL, 10L); /* value 10, print width is 5 (bad type) */
pf("%3$*2$d", 1, 5, 10); /* ok, skipping the '1' */
pf("%3$*2$d", 1, 5, 10L); /* bad print type */
pf("%2$*3$d", 1UL, 10, 5); /* ok, try with swapping width/val */
pf("%2$*3$d", 1UL, 10L, 5); /* bad, try with swapping width/val */
/* and now try with precision specifiers */
pf("%*.6d", 5, 10); /* value 10, print width is 5 */
pf("%*.6d", 5, 10L); /* value 10, print width is 5 (bad type) */
pf("%*.6d", 5UL, 10L); /* value 10, print width is 5 (bad type) */
pf("%*.*d", 5, 6, 10); /* value 10, print width is 5 */
pf("%*.*d", 5, 6, 10L); /* value 10, print width is 5 (bad type) */
pf("%*.*d", 5UL, 6, 10L); /* value 10, print width is 5 (bad type) */
pf("%*.*d", 5, 6UL, 10); /* value 10, print width is 5 (bad type) */
}
/*
* check-name: variadic formatting test position checking types
* check-command: sparse -Wformat $file
* check-known-to-fail
*
* check-error-start
varargs-type-formattest.c:12:9: warning: width: no argument at position 4
varargs-type-formattest.c:12:9: warning: width: no argument at position 5
varargs-type-formattest.c:15:9: warning: incorrect type in argument 3 (different types)
varargs-type-formattest.c:15:9: expected int
varargs-type-formattest.c:15:9: got long
varargs-type-formattest.c:15:9: warning: incorrect type in argument 4 (different types)
varargs-type-formattest.c:15:9: expected int
varargs-type-formattest.c:15:9: got long
varargs-type-formattest.c:16:9: warning: incorrect type for width argument 2
varargs-type-formattest.c:16:9: expected int
varargs-type-formattest.c:16:9: got unsigned long
varargs-type-formattest.c:16:9: warning: incorrect type in argument 3 (different types)
varargs-type-formattest.c:16:9: expected int
varargs-type-formattest.c:16:9: got long
varargs-type-formattest.c:16:9: warning: incorrect type for width argument 3
varargs-type-formattest.c:16:9: expected int
varargs-type-formattest.c:16:9: got unsigned long
varargs-type-formattest.c:16:9: warning: incorrect type in argument 4 (different types)
varargs-type-formattest.c:16:9: expected int
varargs-type-formattest.c:16:9: got long
varargs-type-formattest.c:19:9: warning: incorrect type in argument 4 (different types)
varargs-type-formattest.c:19:9: expected int
varargs-type-formattest.c:19:9: got long
varargs-type-formattest.c:19:9: warning: incorrect type in argument 5 (different types)
varargs-type-formattest.c:19:9: expected int
varargs-type-formattest.c:19:9: got long
varargs-type-formattest.c:21:9: warning: incorrect type in argument 3 (different types)
varargs-type-formattest.c:21:9: expected int
varargs-type-formattest.c:21:9: got long
varargs-type-formattest.c:21:9: warning: incorrect type in argument 4 (different types)
varargs-type-formattest.c:21:9: expected int
varargs-type-formattest.c:21:9: got long
varargs-type-formattest.c:26:9: warning: incorrect type in argument 3 (different types)
varargs-type-formattest.c:26:9: expected int
varargs-type-formattest.c:26:9: got long
varargs-type-formattest.c:26:9: warning: incorrect type in argument 4 (different types)
varargs-type-formattest.c:26:9: expected int
varargs-type-formattest.c:26:9: got long
varargs-type-formattest.c:27:9: warning: incorrect type for width argument 2
varargs-type-formattest.c:27:9: expected int
varargs-type-formattest.c:27:9: got unsigned long
varargs-type-formattest.c:27:9: warning: incorrect type in argument 3 (different types)
varargs-type-formattest.c:27:9: expected int
varargs-type-formattest.c:27:9: got long
varargs-type-formattest.c:27:9: warning: incorrect type for width argument 3
varargs-type-formattest.c:27:9: expected int
varargs-type-formattest.c:27:9: got unsigned long
varargs-type-formattest.c:27:9: warning: incorrect type in argument 4 (different types)
varargs-type-formattest.c:27:9: expected int
varargs-type-formattest.c:27:9: got long
varargs-type-formattest.c:30:9: warning: incorrect type in argument 4 (different types)
varargs-type-formattest.c:30:9: expected int
varargs-type-formattest.c:30:9: got long
varargs-type-formattest.c:30:9: warning: incorrect type in argument 5 (different types)
varargs-type-formattest.c:30:9: expected int
varargs-type-formattest.c:30:9: got long
varargs-type-formattest.c:31:9: warning: incorrect type for width argument 2
varargs-type-formattest.c:31:9: expected int
varargs-type-formattest.c:31:9: got unsigned long
varargs-type-formattest.c:31:9: warning: incorrect type in argument 4 (different types)
varargs-type-formattest.c:31:9: expected int
varargs-type-formattest.c:31:9: got long
varargs-type-formattest.c:31:9: warning: incorrect type for width argument 3
varargs-type-formattest.c:31:9: expected int
varargs-type-formattest.c:31:9: got unsigned long
varargs-type-formattest.c:31:9: warning: incorrect type in argument 5 (different types)
varargs-type-formattest.c:31:9: expected int
varargs-type-formattest.c:31:9: got long
varargs-type-formattest.c:32:9: warning: incorrect type for position argument 3
varargs-type-formattest.c:32:9: expected int
varargs-type-formattest.c:32:9: got unsigned long
varargs-type-formattest.c:32:9: warning: incorrect type for position argument 4
varargs-type-formattest.c:32:9: expected int
varargs-type-formattest.c:32:9: got unsigned long
* check-error-end
*
*/
|