4 * Copyright (C) 2006 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
16 int option_no_data
= 0;
18 typedef void (*reg_func
) (int id
);
19 void register_smatch_extra(int id
);
20 void register_smatch_ignore(int id
);
21 void register_implications(int id
);
22 void register_function_hooks(int id
);
23 void check_debug(int id
);
24 void check_null_deref(int id
);
25 void check_overflow(int id
);
26 void check_locking(int id
);
27 void check_memory(int id
);
28 void check_frees_argument(int id
);
29 void check_puts_argument(int id
);
30 void check_leaks(int id
);
31 void check_type(int id
);
32 void check_allocation_funcs(int id
);
33 void check_err_ptr(int id
);
34 void check_err_ptr_deref(int id
);
35 /* <- your test goes here */
36 /* void register_template(int id); */
38 static const reg_func reg_funcs
[] = {
39 ®ister_smatch_extra
, /* smatch_extra always has to be first */
40 ®ister_smatch_ignore
,
47 // &check_allocation_funcs,
49 // &check_frees_argument,
50 // &check_puts_argument,
54 /* <- your test goes here */
55 /* ®ister_template, */
57 ®ister_implications
, /* implications always has to be last */
61 static void help(void)
63 printf("Usage: smatch [smatch arguments][sparse arguments] file.c\n");
64 printf("--debug: print lots of debug output.\n");
65 printf("--debug-implied: print debug output about implications.\n");
66 printf("--no-implied: ignore implications.\n");
67 printf("--assume-loops: assume loops always go through at least once.\n");
68 printf("--known-conditions: don't branch for known conditions.\n");
69 printf("--no-data: do not use the /smatch_data/ directory.\n");
70 printf("--help: print this helpfull message.\n");
74 void parse_args(int *argcp
, char ***argvp
)
77 if (!strcmp((*argvp
)[1], "--debug")) {
79 (*argvp
)[1] = (*argvp
)[0];
80 } else if (!strcmp((*argvp
)[1], "--debug-implied")) {
81 debug_implied_states
= 1;
82 (*argvp
)[1] = (*argvp
)[0];
83 } else if (!strcmp((*argvp
)[1], "--no-implied")) {
84 option_no_implied
= 1;
85 (*argvp
)[1] = (*argvp
)[0];
86 } else if (!strcmp((*argvp
)[1], "--assume-loops")) {
87 option_assume_loops
= 1;
88 (*argvp
)[1] = (*argvp
)[0];
89 } else if (!strcmp((*argvp
)[1], "--known-conditions")) {
90 option_known_conditions
= 1;
91 (*argvp
)[1] = (*argvp
)[0];
92 } else if (!strcmp((*argvp
)[1], "--no-data")) {
94 (*argvp
)[1] = (*argvp
)[0];
95 } else if (!strcmp((*argvp
)[1], "--help")) {
105 static char *get_data_dir(char *arg0
)
111 if (option_no_data
) {
114 bin_dir
= dirname(alloc_string(arg0
));
115 strncpy(buf
, bin_dir
, 254);
117 strncat(buf
, "/smatch_data/", 254 - strlen(buf
));
118 dir
= alloc_string(buf
);
119 if (!access(dir
, R_OK
))
121 printf("Warning: %s is not accessible.\n", dir
);
122 printf("Use --no-data to suppress this message.\n");
126 int main(int argc
, char **argv
)
131 parse_args(&argc
, &argv
);
133 data_dir
= get_data_dir(argv
[0]);
135 /* The script IDs start at 1.
136 0 is used for internal stuff. */
137 create_function_hash();
138 for(i
= 0; (func
= reg_funcs
[i
]); i
++){
141 register_function_hooks(-1);
144 free_string(data_dir
);