17 * Copyright 2019 Joyent, Inc.
18 */
19
20 #include <stdio.h>
21 #include <unistd.h>
22 #include <libgen.h>
23 #include "smatch.h"
24 #include "smatch_slist.h"
25 #include "check_list.h"
26
27 char *option_debug_check = (char *)"";
28 char *option_project_str = (char *)"smatch_generic";
29 static char *option_db_file = (char *)"smatch_db.sqlite";
30 enum project_type option_project = PROJ_NONE;
31 char *bin_dir;
32 char *data_dir;
33 int option_no_data = 0;
34 int option_spammy = 0;
35 int option_info = 0;
36 int option_full_path = 0;
37 int option_param_mapper = 0;
38 int option_call_tree = 0;
39 int option_no_db = 0;
40 int option_enable = 0;
41 int option_disable = 0;
42 int option_file_output;
43 int option_time;
44 int option_mem;
45 char *option_datadir_str;
46 int option_fatal_checks;
47 int option_succeed;
48 int option_timeout = 60;
49
50 FILE *sm_outfd;
51 FILE *sql_outfd;
52 FILE *caller_info_fd;
53
54 int sm_nr_errors;
55 int sm_nr_checks;
56
57 bool __silence_warnings_for_stmt;
125 if (strcmp(reg_funcs[i].name, buf) == 0) {
126 reg_funcs[i].enabled = (enable == true) ? 1 : -1;
127 break;
128 }
129 }
130
131 if (i == ARRAY_SIZE(reg_funcs))
132 sm_fatal("'%s' not found", s);
133
134 } while ((s = next));
135 }
136
137 static void help(void)
138 {
139 printf("Usage: smatch [smatch arguments][sparse arguments] file.c\n");
140 printf("--project=<name> or -p=<name>: project specific tests\n");
141 printf("--succeed: don't exit with an error\n");
142 printf("--spammy: print superfluous crap.\n");
143 printf("--info: print info used to fill smatch_data/.\n");
144 printf("--debug: print lots of debug output.\n");
145 printf("--param-mapper: enable param_mapper output.\n");
146 printf("--no-data: do not use the /smatch_data/ directory.\n");
147 printf("--data=<dir>: overwrite path to default smatch data directory.\n");
148 printf("--full-path: print the full pathname.\n");
149 printf("--debug-implied: print debug output about implications.\n");
150 printf("--assume-loops: assume loops always go through at least once.\n");
151 printf("--two-passes: use a two pass system for each function.\n");
152 printf("--file-output: instead of printing stdout, print to \"file.c.smatch_out\".\n");
153 printf("--fatal-checks: check output is treated as an error.\n");
154 printf("--help: print this helpful message.\n");
155 exit(1);
156 }
157
158 static int match_option(const char *arg, const char *option)
159 {
160 char *str;
161 char *tmp;
162 int ret = 0;
163
164 str = malloc(strlen(option) + 3);
165 snprintf(str, strlen(option) + 3, "--%s", option);
218 if (strncmp((*argvp)[i], "--disable=", 10) == 0) {
219 enable_disable_checks((*argvp)[i] + 10, 0);
220 option_enable = 1;
221 option_disable = 1;
222 }
223
224 if (!strncmp((*argvp)[i], "--timeout=", 10)) {
225 if (sscanf((*argvp)[i] + 10, "%d",
226 &option_timeout) != 1)
227 sm_fatal("invalid option %s", (*argvp)[i]);
228 }
229
230 OPTION(fatal_checks);
231 OPTION(spammy);
232 OPTION(info);
233 OPTION(debug);
234 OPTION(assume_loops);
235 OPTION(no_data);
236 OPTION(two_passes);
237 OPTION(full_path);
238 OPTION(param_mapper);
239 OPTION(call_tree);
240 OPTION(file_output);
241 OPTION(time);
242 OPTION(mem);
243 OPTION(no_db);
244 OPTION(succeed);
245 }
246
247 if (strcmp(option_project_str, "smatch_generic") != 0)
248 option_project = PROJ_UNKNOWN;
249
250 if (strcmp(option_project_str, "kernel") == 0)
251 option_project = PROJ_KERNEL;
252 else if (strcmp(option_project_str, "wine") == 0)
253 option_project = PROJ_WINE;
254 else if (strcmp(option_project_str, "illumos_kernel") == 0)
255 option_project = PROJ_ILLUMOS_KERNEL;
256 else if (strcmp(option_project_str, "illumos_user") == 0)
257 option_project = PROJ_ILLUMOS_USER;
258 }
|
17 * Copyright 2019 Joyent, Inc.
18 */
19
20 #include <stdio.h>
21 #include <unistd.h>
22 #include <libgen.h>
23 #include "smatch.h"
24 #include "smatch_slist.h"
25 #include "check_list.h"
26
27 char *option_debug_check = (char *)"";
28 char *option_project_str = (char *)"smatch_generic";
29 static char *option_db_file = (char *)"smatch_db.sqlite";
30 enum project_type option_project = PROJ_NONE;
31 char *bin_dir;
32 char *data_dir;
33 int option_no_data = 0;
34 int option_spammy = 0;
35 int option_info = 0;
36 int option_full_path = 0;
37 int option_call_tree = 0;
38 int option_no_db = 0;
39 int option_enable = 0;
40 int option_disable = 0;
41 int option_file_output;
42 int option_time;
43 int option_mem;
44 char *option_datadir_str;
45 int option_fatal_checks;
46 int option_succeed;
47 int option_timeout = 60;
48
49 FILE *sm_outfd;
50 FILE *sql_outfd;
51 FILE *caller_info_fd;
52
53 int sm_nr_errors;
54 int sm_nr_checks;
55
56 bool __silence_warnings_for_stmt;
124 if (strcmp(reg_funcs[i].name, buf) == 0) {
125 reg_funcs[i].enabled = (enable == true) ? 1 : -1;
126 break;
127 }
128 }
129
130 if (i == ARRAY_SIZE(reg_funcs))
131 sm_fatal("'%s' not found", s);
132
133 } while ((s = next));
134 }
135
136 static void help(void)
137 {
138 printf("Usage: smatch [smatch arguments][sparse arguments] file.c\n");
139 printf("--project=<name> or -p=<name>: project specific tests\n");
140 printf("--succeed: don't exit with an error\n");
141 printf("--spammy: print superfluous crap.\n");
142 printf("--info: print info used to fill smatch_data/.\n");
143 printf("--debug: print lots of debug output.\n");
144 printf("--no-data: do not use the /smatch_data/ directory.\n");
145 printf("--data=<dir>: overwrite path to default smatch data directory.\n");
146 printf("--full-path: print the full pathname.\n");
147 printf("--debug-implied: print debug output about implications.\n");
148 printf("--assume-loops: assume loops always go through at least once.\n");
149 printf("--two-passes: use a two pass system for each function.\n");
150 printf("--file-output: instead of printing stdout, print to \"file.c.smatch_out\".\n");
151 printf("--fatal-checks: check output is treated as an error.\n");
152 printf("--help: print this helpful message.\n");
153 exit(1);
154 }
155
156 static int match_option(const char *arg, const char *option)
157 {
158 char *str;
159 char *tmp;
160 int ret = 0;
161
162 str = malloc(strlen(option) + 3);
163 snprintf(str, strlen(option) + 3, "--%s", option);
216 if (strncmp((*argvp)[i], "--disable=", 10) == 0) {
217 enable_disable_checks((*argvp)[i] + 10, 0);
218 option_enable = 1;
219 option_disable = 1;
220 }
221
222 if (!strncmp((*argvp)[i], "--timeout=", 10)) {
223 if (sscanf((*argvp)[i] + 10, "%d",
224 &option_timeout) != 1)
225 sm_fatal("invalid option %s", (*argvp)[i]);
226 }
227
228 OPTION(fatal_checks);
229 OPTION(spammy);
230 OPTION(info);
231 OPTION(debug);
232 OPTION(assume_loops);
233 OPTION(no_data);
234 OPTION(two_passes);
235 OPTION(full_path);
236 OPTION(call_tree);
237 OPTION(file_output);
238 OPTION(time);
239 OPTION(mem);
240 OPTION(no_db);
241 OPTION(succeed);
242 }
243
244 if (strcmp(option_project_str, "smatch_generic") != 0)
245 option_project = PROJ_UNKNOWN;
246
247 if (strcmp(option_project_str, "kernel") == 0)
248 option_project = PROJ_KERNEL;
249 else if (strcmp(option_project_str, "wine") == 0)
250 option_project = PROJ_WINE;
251 else if (strcmp(option_project_str, "illumos_kernel") == 0)
252 option_project = PROJ_ILLUMOS_KERNEL;
253 else if (strcmp(option_project_str, "illumos_user") == 0)
254 option_project = PROJ_ILLUMOS_USER;
255 }
|