Print this page
11506 smatch resync

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/smatch_passes_array_size.c
          +++ new/usr/src/tools/smatch/src/smatch_passes_array_size.c
↓ open down ↓ 31 lines elided ↑ open up ↑
  32   32                  if (val.value == size)
  33   33                          return i;
  34   34          } END_FOR_EACH_PTR(arg);
  35   35  
  36   36          return -1;
  37   37  }
  38   38  
  39   39  static void match_call(struct expression *expr)
  40   40  {
  41   41          struct expression *arg;
  42      -        struct symbol *type;
       42 +        struct symbol *type, *arg_type;
  43   43          int size, bytes;
  44   44          int i, nr;
  45   45          char buf[16];
       46 +        char elem_count[8];
       47 +        char byte_count[8];
  46   48  
       49 +        snprintf(elem_count, sizeof(elem_count), "%d", ELEM_COUNT);
       50 +        snprintf(byte_count, sizeof(byte_count), "%d", BYTE_COUNT);
  47   51  
  48   52          i = -1;
  49   53          FOR_EACH_PTR(expr->args, arg) {
  50   54                  i++;
  51   55                  type = get_type(arg);
  52   56                  if (!type || (type->type != SYM_PTR && type->type != SYM_ARRAY))
  53   57                          continue;
       58 +                arg_type = get_arg_type(expr->fn, i);
       59 +                if (arg_type != type)
       60 +                        continue;
       61 +
  54   62                  size = get_array_size(arg);
  55   63                  if (size > 0) {
  56   64                          nr = find_param_eq(expr, size);
  57   65                          if (nr >= 0) {
  58      -                                snprintf(buf, sizeof(buf), "%d", nr);
  59      -                                sql_insert_caller_info(expr, ARRAYSIZE_ARG, i, buf, "");
       66 +                                snprintf(buf, sizeof(buf), "==$%d", nr);
       67 +                                sql_insert_caller_info(expr, ELEM_COUNT, i, buf, elem_count);
  60   68                                  continue;
  61   69                          }
  62   70                  }
  63   71                  bytes = get_array_size_bytes(arg);
  64   72                  if (bytes > 0) {
  65   73                          nr = find_param_eq(expr, bytes);
  66   74                          if (nr >= 0) {
  67      -                                snprintf(buf, sizeof(buf), "%d", nr);
  68      -                                sql_insert_caller_info(expr, SIZEOF_ARG, i, buf, "");
       75 +                                snprintf(buf, sizeof(buf), "==$%d", nr);
       76 +                                sql_insert_caller_info(expr, BYTE_COUNT, i, buf, byte_count);
  69   77                                  continue;
  70   78                          }
  71   79                  }
  72   80          } END_FOR_EACH_PTR(arg);
  73   81  }
  74   82  
  75   83  void register_passes_array_size(int id)
  76   84  {
  77   85          add_hook(&match_call, FUNCTION_CALL_HOOK);
  78   86  }
  79   87  
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX