Print this page
11462 enable smatch by default
   1 /*
   2  * Copyright (C) 2006 Dan Carpenter.
   3  *
   4  * This program is free software; you can redistribute it and/or
   5  * modify it under the terms of the GNU General Public License
   6  * as published by the Free Software Foundation; either version 2
   7  * of the License, or (at your option) any later version.
   8  *
   9  * This program is distributed in the hope that it will be useful,
  10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  * GNU General Public License for more details.
  13  *
  14  * You should have received a copy of the GNU General Public License
  15  * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt


  16  */
  17 
  18 #include <stdio.h>
  19 #include <unistd.h>
  20 #include <libgen.h>
  21 #include "smatch.h"
  22 #include "check_list.h"
  23 
  24 char *option_debug_check = (char *)"";
  25 char *option_project_str = (char *)"smatch_generic";
  26 static char *option_db_file = (char *)"smatch_db.sqlite";
  27 enum project_type option_project = PROJ_NONE;
  28 char *bin_dir;
  29 char *data_dir;
  30 int option_no_data = 0;
  31 int option_spammy = 0;
  32 int option_info = 0;
  33 int option_full_path = 0;
  34 int option_param_mapper = 0;
  35 int option_call_tree = 0;
  36 int option_no_db = 0;
  37 int option_enable = 0;
  38 int option_disable = 0;
  39 int option_debug_related;
  40 int option_file_output;
  41 int option_time;
  42 int option_mem;
  43 char *option_datadir_str;
  44 int option_fatal_checks;
  45 int option_succeed;

  46 
  47 FILE *sm_outfd;
  48 FILE *sql_outfd;
  49 FILE *caller_info_fd;
  50 
  51 int sm_nr_errors;
  52 int sm_nr_checks;
  53 
  54 bool __silence_warnings_for_stmt;
  55 
  56 const char *progname;
  57 
  58 typedef void (*reg_func) (int id);
  59 #define CK(_x) {.name = #_x, .func = &_x, .enabled = 0},
  60 static struct reg_func_info {
  61         const char *name;
  62         reg_func func;
  63         int enabled;
  64 } reg_funcs[] = {
  65         {NULL, NULL},


 156 {
 157         char *str;
 158         char *tmp;
 159         int ret = 0;
 160 
 161         str = malloc(strlen(option) + 3);
 162         snprintf(str, strlen(option) + 3, "--%s", option);
 163         tmp = str;
 164         while (*tmp) {
 165                 if (*tmp == '_')
 166                         *tmp = '-';
 167                 tmp++;
 168         }
 169         if (!strcmp(arg, str))
 170                 ret = 1;
 171         free(str);
 172         return ret;
 173 }
 174 
 175 #define OPTION(_x) do {                                 \
 176         if (match_option((*argvp)[1], #_x)) {           \
 177                 option_##_x = 1;                        \
 178         }                                               \
 179 } while (0)
 180 
 181 void parse_args(int *argcp, char ***argvp)
 182 {
 183         int i;
 184 
 185         for (i = 1 ; i < *argcp; i++) {
 186                 if (!strcmp((*argvp)[i], "--help"))
 187                         help();
 188 
 189                 if (!strcmp((*argvp)[i], "--show-checks"))
 190                         show_checks();
 191 
 192                 if (!strncmp((*argvp)[i], "--project=", 10))
 193                         option_project_str = (*argvp)[i] + 10;
 194 
 195                 if (!strncmp((*argvp)[i], "-p=", 3))
 196                         option_project_str = (*argvp)[i] + 3;


 201                 if (!strncmp((*argvp)[i], "--data=", 7))
 202                         option_datadir_str = (*argvp)[i] + 7;
 203 
 204                 if (!strncmp((*argvp)[i], "--debug=", 8))
 205                         option_debug_check = (*argvp)[i] + 8;
 206 
 207                 if (strncmp((*argvp)[i], "--trace=", 8) == 0)
 208                         trace_variable = (*argvp)[i] + 8;
 209 
 210                 if (strncmp((*argvp)[i], "--enable=", 9) == 0) {
 211                         enable_disable_checks((*argvp)[i] + 9, 1);
 212                         option_enable = 1;
 213                 }
 214 
 215                 if (strncmp((*argvp)[i], "--disable=", 10) == 0) {
 216                         enable_disable_checks((*argvp)[i] + 10, 0);
 217                         option_enable = 1;
 218                         option_disable = 1;
 219                 }
 220 






 221                 OPTION(fatal_checks);
 222                 OPTION(spammy);
 223                 OPTION(info);
 224                 OPTION(debug);
 225                 OPTION(debug_implied);
 226                 OPTION(debug_related);
 227                 OPTION(assume_loops);
 228                 OPTION(no_data);
 229                 OPTION(two_passes);
 230                 OPTION(full_path);
 231                 OPTION(param_mapper);
 232                 OPTION(call_tree);
 233                 OPTION(file_output);
 234                 OPTION(time);
 235                 OPTION(mem);
 236                 OPTION(no_db);
 237                 OPTION(succeed);
 238         }
 239 
 240         if (strcmp(option_project_str, "smatch_generic") != 0)


   1 /*
   2  * Copyright (C) 2006 Dan Carpenter.
   3  *
   4  * This program is free software; you can redistribute it and/or
   5  * modify it under the terms of the GNU General Public License
   6  * as published by the Free Software Foundation; either version 2
   7  * of the License, or (at your option) any later version.
   8  *
   9  * This program is distributed in the hope that it will be useful,
  10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  * GNU General Public License for more details.
  13  *
  14  * You should have received a copy of the GNU General Public License
  15  * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
  16  *
  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 "check_list.h"
  25 
  26 char *option_debug_check = (char *)"";
  27 char *option_project_str = (char *)"smatch_generic";
  28 static char *option_db_file = (char *)"smatch_db.sqlite";
  29 enum project_type option_project = PROJ_NONE;
  30 char *bin_dir;
  31 char *data_dir;
  32 int option_no_data = 0;
  33 int option_spammy = 0;
  34 int option_info = 0;
  35 int option_full_path = 0;
  36 int option_param_mapper = 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_debug_related;
  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;
  58 
  59 const char *progname;
  60 
  61 typedef void (*reg_func) (int id);
  62 #define CK(_x) {.name = #_x, .func = &_x, .enabled = 0},
  63 static struct reg_func_info {
  64         const char *name;
  65         reg_func func;
  66         int enabled;
  67 } reg_funcs[] = {
  68         {NULL, NULL},


 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);
 166         tmp = str;
 167         while (*tmp) {
 168                 if (*tmp == '_')
 169                         *tmp = '-';
 170                 tmp++;
 171         }
 172         if (!strcmp(arg, str))
 173                 ret = 1;
 174         free(str);
 175         return ret;
 176 }
 177 
 178 #define OPTION(_x) do {                                 \
 179         if (match_option((*argvp)[i], #_x)) {           \
 180                 option_##_x = 1;                        \
 181         }                                               \
 182 } while (0)
 183 
 184 void parse_args(int *argcp, char ***argvp)
 185 {
 186         int i;
 187 
 188         for (i = 1 ; i < *argcp; i++) {
 189                 if (!strcmp((*argvp)[i], "--help"))
 190                         help();
 191 
 192                 if (!strcmp((*argvp)[i], "--show-checks"))
 193                         show_checks();
 194 
 195                 if (!strncmp((*argvp)[i], "--project=", 10))
 196                         option_project_str = (*argvp)[i] + 10;
 197 
 198                 if (!strncmp((*argvp)[i], "-p=", 3))
 199                         option_project_str = (*argvp)[i] + 3;


 204                 if (!strncmp((*argvp)[i], "--data=", 7))
 205                         option_datadir_str = (*argvp)[i] + 7;
 206 
 207                 if (!strncmp((*argvp)[i], "--debug=", 8))
 208                         option_debug_check = (*argvp)[i] + 8;
 209 
 210                 if (strncmp((*argvp)[i], "--trace=", 8) == 0)
 211                         trace_variable = (*argvp)[i] + 8;
 212 
 213                 if (strncmp((*argvp)[i], "--enable=", 9) == 0) {
 214                         enable_disable_checks((*argvp)[i] + 9, 1);
 215                         option_enable = 1;
 216                 }
 217 
 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(debug_implied);
 235                 OPTION(debug_related);
 236                 OPTION(assume_loops);
 237                 OPTION(no_data);
 238                 OPTION(two_passes);
 239                 OPTION(full_path);
 240                 OPTION(param_mapper);
 241                 OPTION(call_tree);
 242                 OPTION(file_output);
 243                 OPTION(time);
 244                 OPTION(mem);
 245                 OPTION(no_db);
 246                 OPTION(succeed);
 247         }
 248 
 249         if (strcmp(option_project_str, "smatch_generic") != 0)