4 * Copyright (C) 2006 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
15 char *option_project_str
= (char *)"";
16 enum project_type option_project
= PROJ_NONE
;
18 int option_no_data
= 0;
19 int option_spammy
= 0;
20 int option_full_path
= 0;
22 typedef void (*reg_func
) (int id
);
23 void register_smatch_extra(int id
);
24 void register_smatch_ignore(int id
);
25 void register_implications(int id
);
26 void register_function_hooks(int id
);
27 void register_modification_hooks(int id
);
28 void register_containers(int id
);
29 void check_debug(int id
);
30 void check_assigned_expr(int id
);
31 void check_null_deref(int id
);
32 void check_overflow(int id
);
33 void check_locking(int id
);
34 void check_memory(int id
);
35 void check_frees_argument(int id
);
36 void check_puts_argument(int id
);
37 void check_leaks(int id
);
38 void check_type(int id
);
39 void check_allocation_funcs(int id
);
40 void check_err_ptr(int id
);
41 void check_err_ptr_deref(int id
);
42 void check_balanced(int id
);
43 void check_deref_check(int id
);
44 void check_hold_dev(int id
);
45 void check_redundant_null_check(int id
);
46 /* <- your test goes here */
48 /* may as well put wine scripts all together */
49 void check_wine(int id
);
50 void check_wine_filehandles(int id
);
51 void check_wine_WtoA(int id
);
52 void check_wine_locking(int id
);
54 /* void register_template(int id); */
56 static const reg_func reg_funcs
[] = {
57 ®ister_smatch_extra
, /* smatch_extra always has to be first */
58 ®ister_smatch_ignore
,
66 &check_allocation_funcs
,
68 &check_frees_argument
,
71 &check_redundant_null_check
,
73 /* <- your test goes here */
74 /* ®ister_template, */
83 /* wine specific stuff */
85 &check_wine_filehandles
,
89 ®ister_modification_hooks
,
91 ®ister_implications
, /* implications always has to be last */
95 struct smatch_state
*default_state
[sizeof(reg_funcs
)/sizeof(reg_func
)];
97 static void help(void)
99 printf("Usage: smatch [smatch arguments][sparse arguments] file.c\n");
100 printf("--project=<name> or -p=<name>: project specific tests\n");
101 printf("--spammy: print superfluous crap.\n");
102 printf("--debug: print lots of debug output.\n");
103 printf("--no-data: do not use the /smatch_data/ directory.\n");
104 printf("--full-path: print the full pathname.\n");
105 printf("--debug-implied: print debug output about implications.\n");
106 printf("--oom <num>: number of mB memory to use before giving up.\n");
107 printf("--no-implied: ignore implications.\n");
108 printf("--assume-loops: assume loops always go through at least once.\n");
109 printf("--known-conditions: don't branch for known conditions.\n");
110 printf("--two-passes: use a two pass system for each function.\n");
111 printf("--help: print this helpfull message.\n");
115 void parse_args(int *argcp
, char ***argvp
)
118 if (!strncmp((*argvp
)[1], "--project=", 10)) {
119 option_project_str
= (*argvp
)[1] + 10;
120 (*argvp
)[1] = (*argvp
)[0];
121 } else if (!strncmp((*argvp
)[1], "-p=", 3)) {
122 option_project_str
= (*argvp
)[1] + 3;
123 (*argvp
)[1] = (*argvp
)[0];
124 } else if (!strcmp((*argvp
)[1], "--debug")) {
126 (*argvp
)[1] = (*argvp
)[0];
127 } else if (!strcmp((*argvp
)[1], "--debug-implied")) {
128 debug_implied_states
= 1;
129 (*argvp
)[1] = (*argvp
)[0];
130 } else if (!strcmp((*argvp
)[1], "--oom")) {
131 option_oom_kb
= atoi((*argvp
)[2]) * 1000;
132 (*argvp
)[2] = (*argvp
)[0];
135 } else if (!strcmp((*argvp
)[1], "--no-implied")) {
136 option_no_implied
= 1;
137 (*argvp
)[1] = (*argvp
)[0];
138 } else if (!strcmp((*argvp
)[1], "--assume-loops")) {
139 option_assume_loops
= 1;
140 (*argvp
)[1] = (*argvp
)[0];
141 } else if (!strcmp((*argvp
)[1], "--known-conditions")) {
142 option_known_conditions
= 1;
143 (*argvp
)[1] = (*argvp
)[0];
144 } else if (!strcmp((*argvp
)[1], "--no-data")) {
146 (*argvp
)[1] = (*argvp
)[0];
147 } else if (!strcmp((*argvp
)[1], "--spammy")) {
149 (*argvp
)[1] = (*argvp
)[0];
150 } else if (!strcmp((*argvp
)[1], "--two-passes")) {
151 option_two_passes
= 1;
152 (*argvp
)[1] = (*argvp
)[0];
153 } else if (!strcmp((*argvp
)[1], "--full-path")) {
154 option_full_path
= 1;
155 (*argvp
)[1] = (*argvp
)[0];
156 } else if (!strcmp((*argvp
)[1], "--help")) {
165 if (!strcmp(option_project_str
, "kernel"))
166 option_project
= PROJ_KERNEL
;
167 if (!strcmp(option_project_str
, "wine"))
168 option_project
= PROJ_WINE
;
171 static char *get_data_dir(char *arg0
)
177 if (option_no_data
) {
180 bin_dir
= dirname(alloc_string(arg0
));
181 strncpy(buf
, bin_dir
, 254);
183 strncat(buf
, "/smatch_data/", 254 - strlen(buf
));
184 dir
= alloc_string(buf
);
185 if (!access(dir
, R_OK
))
187 printf("Warning: %s is not accessible.\n", dir
);
188 printf("Use --no-data to suppress this message.\n");
192 int main(int argc
, char **argv
)
197 parse_args(&argc
, &argv
);
199 data_dir
= get_data_dir(argv
[0]);
201 /* The script IDs start at 1.
202 0 is used for internal stuff. */
203 create_function_hash();
204 for(i
= 0; (func
= reg_funcs
[i
]); i
++){
207 register_function_hooks(-1);
210 free_string(data_dir
);