Print this page
11506 smatch resync

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/smatch_helper.c
          +++ new/usr/src/tools/smatch/src/smatch_helper.c
↓ open down ↓ 73 lines elided ↑ open up ↑
  74   74  
  75   75  struct smatch_state *alloc_state_str(const char *name)
  76   76  {
  77   77          struct smatch_state *state;
  78   78  
  79   79          state = __alloc_smatch_state(0);
  80   80          state->name = alloc_string(name);
  81   81          return state;
  82   82  }
  83   83  
       84 +struct smatch_state *merge_str_state(struct smatch_state *s1, struct smatch_state *s2)
       85 +{
       86 +        if (!s1->name || !s2->name)
       87 +                return &merged;
       88 +        if (strcmp(s1->name, s2->name) == 0)
       89 +                return s1;
       90 +        return &merged;
       91 +}
       92 +
  84   93  struct smatch_state *alloc_state_expr(struct expression *expr)
  85   94  {
  86   95          struct smatch_state *state;
  87   96          char *name;
  88   97  
  89      -        state = __alloc_smatch_state(0);
  90   98          expr = strip_expr(expr);
  91   99          name = expr_to_str(expr);
      100 +        if (!name)
      101 +                return NULL;
      102 +
      103 +        state = __alloc_smatch_state(0);
  92  104          state->name = alloc_sname(name);
  93  105          free_string(name);
  94  106          state->data = expr;
  95  107          return state;
  96  108  }
  97  109  
  98  110  void append(char *dest, const char *data, int buff_len)
  99  111  {
 100  112          strncat(dest, data, buff_len - strlen(dest) - 1);
 101  113  }
↓ open down ↓ 57 lines elided ↑ open up ↑
 159  171                  return;
 160  172          }
 161  173  
 162  174          switch (expr->type) {
 163  175          case EXPR_DEREF: {
 164  176                  struct expression *deref;
 165  177                  int op;
 166  178  
 167  179                  deref = expr->deref;
 168  180                  op = deref->op;
 169      -                if (op == '*') {
      181 +                if (deref->type == EXPR_PREOP && op == '*') {
 170  182                          struct expression *unop = strip_expr(deref->unop);
 171  183  
 172  184                          if (unop->type == EXPR_PREOP && unop->op == '&') {
 173  185                                  deref = unop->unop;
 174  186                                  op = '.';
 175  187                          } else {
 176      -                                deref = deref->unop;
 177      -                                if (!is_pointer(deref))
      188 +                                if (!is_pointer(deref) && !is_pointer(deref->unop))
 178  189                                          op = '.';
      190 +                                deref = deref->unop;
 179  191                          }
 180  192                  }
 181  193  
 182  194                  __get_variable_from_expr(sym_ptr, buf, deref, len, complicated, no_parens);
 183  195  
 184  196                  if (op == '*')
 185  197                          append(buf, "->", len);
 186  198                  else
 187  199                          append(buf, ".", len);
 188  200  
↓ open down ↓ 331 lines elided ↑ open up ↑
 520  532  
 521  533          expr = strip_parens(expr);
 522  534          if (!expr)
 523  535                  return NULL;
 524  536  
 525  537          name = expr_to_var_sym(expr, &tmp);
 526  538          if (name && tmp) {
 527  539                  if (sym)
 528  540                          *sym = tmp;
 529  541                  if (vsl)
 530      -                        *vsl = expr_to_vsl(expr);
      542 +                        add_var_sym(vsl, name, tmp);
 531  543                  return name;
 532  544          }
 533  545          free_string(name);
 534  546  
 535  547          score = get_complication_score(expr);
 536  548          if (score <= 0 || score > 2)
 537  549                  return NULL;
 538  550  
 539  551          tmp_vsl = expr_to_vsl(expr);
 540  552          if (vsl) {
↓ open down ↓ 321 lines elided ↑ open up ↑
 862  874  
 863  875          sym = get_type(expr->deref);
 864  876          if (!sym)
 865  877                  return NULL;
 866  878          if (sym->type == SYM_UNION) {
 867  879                  snprintf(buf, sizeof(buf), "(union %s)->%s",
 868  880                           sym->ident ? sym->ident->name : "anonymous",
 869  881                           expr->member->name);
 870  882                  return alloc_string(buf);
 871  883          }
 872      -        if (!sym->ident)
 873      -                return NULL;
      884 +        if (!sym->ident) {
      885 +                struct expression *deref;
      886 +                char *full, *outer;
      887 +                int len;
      888 +
      889 +                /*
      890 +                 * If we're in an anonymous struct then maybe we can find an
      891 +                 * outer struct name to use as a name.  This code should be
      892 +                 * recursive and cleaner.  I am not very proud of it.
      893 +                 *
      894 +                 */
      895 +
      896 +                deref = expr->deref;
      897 +                if (deref->type != EXPR_DEREF || !deref->member)
      898 +                        return NULL;
      899 +                sym = get_type(deref->deref);
      900 +                if (!sym || sym->type != SYM_STRUCT || !sym->ident)
      901 +                        return NULL;
      902 +
      903 +                full = expr_to_str(expr);
      904 +                if (!full)
      905 +                        return NULL;
      906 +                deref = deref->deref;
      907 +                if (deref->type == EXPR_PREOP && deref->op == '*')
      908 +                        deref = deref->unop;
      909 +                outer = expr_to_str(deref);
      910 +                if (!outer) {
      911 +                        free_string(full);
      912 +                        return NULL;
      913 +                }
      914 +                len = strlen(outer);
      915 +                if (strncmp(outer, full, len) != 0) {
      916 +                        free_string(full);
      917 +                        free_string(outer);
      918 +                        return NULL;
      919 +                }
      920 +                if (full[len] == '-' && full[len + 1] == '>')
      921 +                        len += 2;
      922 +                if (full[len] == '.')
      923 +                        len++;
      924 +                snprintf(buf, sizeof(buf), "(struct %s)->%s", sym->ident->name, full + len);
      925 +                free_string(outer);
      926 +                free_string(full);
      927 +
      928 +                return alloc_string(buf);
      929 +        }
 874  930          snprintf(buf, sizeof(buf), "(struct %s)->%s", sym->ident->name, expr->member->name);
 875  931          return alloc_string(buf);
 876  932  }
 877  933  
 878  934  int cmp_pos(struct position pos1, struct position pos2)
 879  935  {
 880  936          /* the stream position is ... */
 881  937          if (pos1.stream > pos2.stream)
 882  938                  return -1;
 883  939          if (pos1.stream < pos2.stream)
↓ open down ↓ 163 lines elided ↑ open up ↑
1047 1103          case '-':
1048 1104                  return '+';
1049 1105          case SPECIAL_LEFTSHIFT:
1050 1106                  return SPECIAL_RIGHTSHIFT;
1051 1107          case SPECIAL_RIGHTSHIFT:
1052 1108                  return SPECIAL_LEFTSHIFT;
1053 1109          }
1054 1110          return 0;
1055 1111  }
1056 1112  
     1113 +int op_remove_assign(int op)
     1114 +{
     1115 +        switch (op) {
     1116 +        case SPECIAL_ADD_ASSIGN:
     1117 +                return '+';
     1118 +        case SPECIAL_SUB_ASSIGN:
     1119 +                return '-';
     1120 +        case SPECIAL_MUL_ASSIGN:
     1121 +                return '*';
     1122 +        case SPECIAL_DIV_ASSIGN:
     1123 +                return '/';
     1124 +        case SPECIAL_MOD_ASSIGN:
     1125 +                return '%';
     1126 +        case SPECIAL_AND_ASSIGN:
     1127 +                return '&';
     1128 +        case SPECIAL_OR_ASSIGN:
     1129 +                return '|';
     1130 +        case SPECIAL_XOR_ASSIGN:
     1131 +                return '^';
     1132 +        case SPECIAL_SHL_ASSIGN:
     1133 +                return SPECIAL_LEFTSHIFT;
     1134 +        case SPECIAL_SHR_ASSIGN:
     1135 +                return SPECIAL_RIGHTSHIFT;
     1136 +        default:
     1137 +                return op;
     1138 +        }
     1139 +}
     1140 +
1057 1141  int expr_equiv(struct expression *one, struct expression *two)
1058 1142  {
1059 1143          struct symbol *one_sym = NULL;
1060 1144          struct symbol *two_sym = NULL;
1061 1145          char *one_name = NULL;
1062 1146          char *two_name = NULL;
1063 1147          int ret = 0;
1064 1148  
1065 1149          if (!one || !two)
1066 1150                  return 0;
↓ open down ↓ 52 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX