Print this page
new smatch


  52         match_strlen(call, NULL, rl);
  53         limit = get_argument_from_call_expr(call->args, 1);
  54         if (!get_implied_max(limit, &bound))
  55                 return 1;
  56         if (sval_cmp(bound, ulong_max) == 0)
  57                 return 1;
  58         if (rl_to_sval(*rl, &fixed) && sval_cmp(fixed, bound) >= 0) {
  59                 *rl = alloc_rl(bound, bound);
  60                 return 1;
  61         }
  62 
  63         bound.value++;
  64         *rl = remove_range(*rl, bound, ulong_max);
  65 
  66         return 1;
  67 }
  68 
  69 static int match_sprintf(struct expression *call, void *_arg, struct range_list **rl)
  70 {
  71         int str_arg = PTR_INT(_arg);
  72         int size;
  73 
  74         size = get_formatted_string_size(call, str_arg);
  75         if (size <= 0) {

  76                 *rl = alloc_whole_rl(&ulong_ctype);
  77         } else {
  78                 /* FIXME:  This is bogus.  get_formatted_string_size() should be
  79                    returning a range_list.  Also it should not add the NUL. */
  80                 size--;
  81                 *rl = alloc_rl(ll_to_sval(0), ll_to_sval(size));
  82         }
  83         return 1;
  84 }
  85 
  86 void register_common_functions(int id)
  87 {
  88         /*
  89          * When you add a new function here, then don't forget to delete it from
  90          * the database and smatch_data/.
  91          */
  92         add_implied_return_hook("strlen", &match_strlen, NULL);
  93         add_implied_return_hook("strnlen", &match_strnlen, NULL);
  94         add_implied_return_hook("sprintf", &match_sprintf, INT_PTR(1));
  95         add_implied_return_hook("snprintf", &match_sprintf, INT_PTR(2));
  96 }


  52         match_strlen(call, NULL, rl);
  53         limit = get_argument_from_call_expr(call->args, 1);
  54         if (!get_implied_max(limit, &bound))
  55                 return 1;
  56         if (sval_cmp(bound, ulong_max) == 0)
  57                 return 1;
  58         if (rl_to_sval(*rl, &fixed) && sval_cmp(fixed, bound) >= 0) {
  59                 *rl = alloc_rl(bound, bound);
  60                 return 1;
  61         }
  62 
  63         bound.value++;
  64         *rl = remove_range(*rl, bound, ulong_max);
  65 
  66         return 1;
  67 }
  68 
  69 static int match_sprintf(struct expression *call, void *_arg, struct range_list **rl)
  70 {
  71         int str_arg = PTR_INT(_arg);
  72         int min, max;
  73 
  74         min = get_formatted_string_min_size(call, str_arg);
  75         max = get_formatted_string_size(call, str_arg);
  76         if (min < 0 || max < 0) {
  77                 *rl = alloc_whole_rl(&ulong_ctype);
  78         } else {
  79                 *rl = alloc_rl(ll_to_sval(min), ll_to_sval(max));
  80                 *rl = cast_rl(get_type(call), *rl);


  81         }
  82         return 1;
  83 }
  84 
  85 void register_common_functions(int id)
  86 {
  87         /*
  88          * When you add a new function here, then don't forget to delete it from
  89          * the database and smatch_data/.
  90          */
  91         add_implied_return_hook("strlen", &match_strlen, NULL);
  92         add_implied_return_hook("strnlen", &match_strnlen, NULL);
  93         add_implied_return_hook("sprintf", &match_sprintf, INT_PTR(1));
  94         add_implied_return_hook("snprintf", &match_sprintf, INT_PTR(2));
  95 }