Print this page
smatch: check libld_* allocation functions


  67 
  68 static void match_calloc(const char *fn, struct expression *expr, void *_arg_nr)
  69 {
  70         int arg_nr = PTR_INT(_arg_nr);
  71         struct expression *call = strip_expr(expr->right);
  72         struct expression *arg;
  73         int ptr_size;
  74 
  75         ptr_size = get_data_size(expr->left);
  76         if (!ptr_size)
  77                 return;
  78 
  79         arg = get_argument_from_call_expr(call->args, arg_nr);
  80         check_size_matches(ptr_size, arg);
  81 }
  82 
  83 void check_kmalloc_wrong_size(int id)
  84 {
  85         my_id = id;
  86 
  87         if (option_project != PROJ_KERNEL) {




  88                 add_function_assign_hook("malloc", &match_alloc, NULL);
  89                 add_function_assign_hook("calloc", &match_calloc, INT_PTR(1));
  90                 return;
  91         }
  92 
  93         add_function_assign_hook("kmalloc", &match_alloc, NULL);
  94         add_function_assign_hook("kcalloc", &match_calloc, INT_PTR(1));
  95 }


  67 
  68 static void match_calloc(const char *fn, struct expression *expr, void *_arg_nr)
  69 {
  70         int arg_nr = PTR_INT(_arg_nr);
  71         struct expression *call = strip_expr(expr->right);
  72         struct expression *arg;
  73         int ptr_size;
  74 
  75         ptr_size = get_data_size(expr->left);
  76         if (!ptr_size)
  77                 return;
  78 
  79         arg = get_argument_from_call_expr(call->args, arg_nr);
  80         check_size_matches(ptr_size, arg);
  81 }
  82 
  83 void check_kmalloc_wrong_size(int id)
  84 {
  85         my_id = id;
  86 
  87         if (option_project == PROJ_KERNEL) {
  88                 add_function_assign_hook("kmalloc", &match_alloc, NULL);
  89                 add_function_assign_hook("kcalloc", &match_calloc, INT_PTR(1));
  90         }
  91         
  92         add_function_assign_hook("malloc", &match_alloc, NULL);
  93         add_function_assign_hook("calloc", &match_calloc, INT_PTR(1));


  94 
  95         if (option_project == PROJ_ILLUMOS_USER)
  96                 add_function_assign_hook("libld_calloc", &match_calloc, INT_PTR(1));
  97 }