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;
21 typedef void (*reg_func
) (int id
);
22 void register_smatch_extra(int id
);
23 void register_smatch_ignore(int id
);
24 void register_implications(int id
);
25 void register_function_hooks(int id
);
26 void register_modification_hooks(int id
);
27 void register_containers(int id
);
28 void check_debug(int id
);
29 void check_assigned_expr(int id
);
30 void check_null_deref(int id
);
31 void check_overflow(int id
);
32 void check_locking(int id
);
33 void check_memory(int id
);
34 void check_frees_argument(int id
);
35 void check_puts_argument(int id
);
36 void check_leaks(int id
);
37 void check_type(int id
);
38 void check_allocation_funcs(int id
);
39 void check_err_ptr(int id
);
40 void check_err_ptr_deref(int id
);
41 void check_balanced(int id
);
42 void check_deref_check(int id
);
43 void check_hold_dev(int id
);
44 void check_redundant_null_check(int id
);
45 /* <- your test goes here */
47 /* may as well put wine scripts all together */
48 void check_wine_filehandles(int id
);
49 void check_wine_WtoA(int id
);
51 /* void register_template(int id); */
53 static const reg_func reg_funcs
[] = {
54 ®ister_smatch_extra
, /* smatch_extra always has to be first */
55 ®ister_smatch_ignore
,
63 &check_allocation_funcs
,
65 &check_frees_argument
,
68 &check_redundant_null_check
,
70 /* <- your test goes here */
71 /* ®ister_template, */
80 /* wine specific stuff */
81 &check_wine_filehandles
,
85 ®ister_modification_hooks
,
87 ®ister_implications
, /* implications always has to be last */
91 struct smatch_state
*default_state
[sizeof(reg_funcs
)/sizeof(reg_func
)];
93 static void help(void)
95 printf("Usage: smatch [smatch arguments][sparse arguments] file.c\n");
96 printf("--project=<name> or -p=<name>: project specific tests\n");
97 printf("--debug: print lots of debug output.\n");
98 printf("--debug-implied: print debug output about implications.\n");
99 printf("--oom <num>: number of mB memory to use before giving up.\n");
100 printf("--no-implied: ignore implications.\n");
101 printf("--assume-loops: assume loops always go through at least once.\n");
102 printf("--known-conditions: don't branch for known conditions.\n");
103 printf("--no-data: do not use the /smatch_data/ directory.\n");
104 printf("--spammy: print superfluous crap.\n");
105 printf("--two-passes: use a two pass system for each function.\n");
106 printf("--help: print this helpfull message.\n");
110 void parse_args(int *argcp
, char ***argvp
)
113 if (!strncmp((*argvp
)[1], "--project=", 10)) {
114 option_project_str
= (*argvp
)[1] + 10;
115 (*argvp
)[1] = (*argvp
)[0];
116 } else if (!strncmp((*argvp
)[1], "-p=", 3)) {
117 option_project_str
= (*argvp
)[1] + 3;
118 (*argvp
)[1] = (*argvp
)[0];
119 } else if (!strcmp((*argvp
)[1], "--debug")) {
121 (*argvp
)[1] = (*argvp
)[0];
122 } else if (!strcmp((*argvp
)[1], "--debug-implied")) {
123 debug_implied_states
= 1;
124 (*argvp
)[1] = (*argvp
)[0];
125 } else if (!strcmp((*argvp
)[1], "--oom")) {
126 option_oom_kb
= atoi((*argvp
)[2]) * 1000;
127 (*argvp
)[2] = (*argvp
)[0];
130 } else if (!strcmp((*argvp
)[1], "--no-implied")) {
131 option_no_implied
= 1;
132 (*argvp
)[1] = (*argvp
)[0];
133 } else if (!strcmp((*argvp
)[1], "--assume-loops")) {
134 option_assume_loops
= 1;
135 (*argvp
)[1] = (*argvp
)[0];
136 } else if (!strcmp((*argvp
)[1], "--known-conditions")) {
137 option_known_conditions
= 1;
138 (*argvp
)[1] = (*argvp
)[0];
139 } else if (!strcmp((*argvp
)[1], "--no-data")) {
141 (*argvp
)[1] = (*argvp
)[0];
142 } else if (!strcmp((*argvp
)[1], "--spammy")) {
144 (*argvp
)[1] = (*argvp
)[0];
145 } else if (!strcmp((*argvp
)[1], "--two-passes")) {
146 option_two_passes
= 1;
147 (*argvp
)[1] = (*argvp
)[0];
148 } else if (!strcmp((*argvp
)[1], "--help")) {
157 if (!strcmp(option_project_str
, "kernel"))
158 option_project
= PROJ_KERNEL
;
159 if (!strcmp(option_project_str
, "wine"))
160 option_project
= PROJ_WINE
;
163 static char *get_data_dir(char *arg0
)
169 if (option_no_data
) {
172 bin_dir
= dirname(alloc_string(arg0
));
173 strncpy(buf
, bin_dir
, 254);
175 strncat(buf
, "/smatch_data/", 254 - strlen(buf
));
176 dir
= alloc_string(buf
);
177 if (!access(dir
, R_OK
))
179 printf("Warning: %s is not accessible.\n", dir
);
180 printf("Use --no-data to suppress this message.\n");
184 int main(int argc
, char **argv
)
189 parse_args(&argc
, &argv
);
191 data_dir
= get_data_dir(argv
[0]);
193 /* The script IDs start at 1.
194 0 is used for internal stuff. */
195 create_function_hash();
196 for(i
= 0; (func
= reg_funcs
[i
]); i
++){
199 register_function_hooks(-1);
202 free_string(data_dir
);