Print this page
12257 resync smatch to 0.6.1-rc1-il-4


 198 
 199         if (!container || container->type != EXPR_SYMBOL)
 200                 return NULL;
 201         if (!expr || expr->type != EXPR_SYMBOL)
 202                 return NULL;
 203         state = get_state_expr(param_id, expr);
 204         if (!state)
 205                 return NULL;
 206 
 207         snprintf(buf, sizeof(buf), "%s", state->name);
 208         p = strchr(buf, '|');
 209         if (!p)
 210                 return NULL;
 211         *p = '\0';
 212         param = atoi(p + 2);
 213         if (get_param_sym_from_num(param) == container->symbol)
 214                 return buf;
 215         return NULL;
 216 }
 217 
 218 char *get_container_name(struct expression *container, struct expression *expr)
 219 {
 220         struct symbol *container_sym, *sym;
 221         struct expression *tmp;
 222         static char buf[64];
 223         char *ret, *shared;
 224         bool star;
 225         int cnt;
 226 
 227         expr = strip_expr(expr);
 228         container = strip_expr(container);


 229 
 230         ret = get_stored_container_name(container, expr);
 231         if (ret)
 232                 return ret;
 233 
 234         sym = expr_to_sym(expr);
 235         container_sym = expr_to_sym(container);
 236         if (sym && sym == container_sym)
 237                 goto found;


 238 
 239         cnt = 0;
 240         while ((tmp = get_assigned_expr(container))) {
 241                 container = strip_expr(tmp);
 242                 if (cnt++ > 3)
 243                         break;
 244         }
 245 
 246         cnt = 0;
 247         while ((tmp = get_assigned_expr(expr))) {
 248                 expr = strip_expr(tmp);
 249                 if (cnt++ > 3)
 250                         break;
 251         }
 252 
 253 found:
 254 
 255         if (container->type == EXPR_DEREF)
 256                 star = true;
 257         else
 258                 star = false;
 259 
 260         if (container->type == EXPR_PREOP && container->op == '&')
 261                 container = strip_expr(container->unop);
 262         if (expr->type == EXPR_PREOP && expr->op == '&')
 263                 expr = strip_expr(expr->unop);
 264 
 265         sym = expr_to_sym(expr);
 266         if (!sym)
 267                 return NULL;
 268         container_sym = expr_to_sym(container);
 269         if (!container_sym || sym != container_sym)
 270                 return NULL;
 271 
 272         shared = get_shared_str(expr, container);
 273         if (!shared)
 274                 return NULL;
 275         if (star)
 276                 snprintf(buf, sizeof(buf), "*(%s)", shared);
 277         else
 278                 snprintf(buf, sizeof(buf), "%s", shared);
 279 
 280         return buf;
 281 }
 282 
























 283 static bool is_fn_ptr(struct expression *expr)
 284 {
 285         struct symbol *type;
 286 
 287         if (!expr)
 288                 return false;
 289         if (expr->type != EXPR_SYMBOL && expr->type != EXPR_DEREF)
 290                 return false;
 291 
 292         type = get_type(expr);
 293         if (!type || type->type != SYM_PTR)
 294                 return false;
 295         type = get_real_base_type(type);
 296         if (!type || type->type != SYM_FN)
 297                 return false;
 298         return true;
 299 }
 300 
 301 static void match_call(struct expression *call)
 302 {




 198 
 199         if (!container || container->type != EXPR_SYMBOL)
 200                 return NULL;
 201         if (!expr || expr->type != EXPR_SYMBOL)
 202                 return NULL;
 203         state = get_state_expr(param_id, expr);
 204         if (!state)
 205                 return NULL;
 206 
 207         snprintf(buf, sizeof(buf), "%s", state->name);
 208         p = strchr(buf, '|');
 209         if (!p)
 210                 return NULL;
 211         *p = '\0';
 212         param = atoi(p + 2);
 213         if (get_param_sym_from_num(param) == container->symbol)
 214                 return buf;
 215         return NULL;
 216 }
 217 
 218 static char *get_container_name_helper(struct expression *container, struct expression *expr)
 219 {
 220         struct symbol *container_sym, *sym;

 221         static char buf[64];
 222         char *ret, *shared;
 223         bool star;

 224 
 225         expr = strip_expr(expr);
 226         container = strip_expr(container);
 227         if (!expr || !container)
 228                 return NULL;
 229 
 230         ret = get_stored_container_name(container, expr);
 231         if (ret)
 232                 return ret;
 233 
 234         sym = expr_to_sym(expr);
 235         container_sym = expr_to_sym(container);
 236         if (!sym || !container_sym)
 237                 return NULL;
 238         if (sym != container_sym)
 239                 return NULL;
 240 
















 241         if (container->type == EXPR_DEREF)
 242                 star = true;
 243         else
 244                 star = false;
 245 
 246         if (container->type == EXPR_PREOP && container->op == '&')
 247                 container = strip_expr(container->unop);
 248         if (expr->type == EXPR_PREOP && expr->op == '&')
 249                 expr = strip_expr(expr->unop);
 250 







 251         shared = get_shared_str(expr, container);
 252         if (!shared)
 253                 return NULL;
 254         if (star)
 255                 snprintf(buf, sizeof(buf), "*(%s)", shared);
 256         else
 257                 snprintf(buf, sizeof(buf), "%s", shared);
 258 
 259         return buf;
 260 }
 261 
 262 char *get_container_name(struct expression *container, struct expression *expr)
 263 {
 264         char *ret;
 265 
 266         ret = get_container_name_helper(container, expr);
 267         if (ret)
 268                 return ret;
 269 
 270         ret = get_container_name_helper(get_assigned_expr(container), expr);
 271         if (ret)
 272                 return ret;
 273 
 274         ret = get_container_name_helper(container, get_assigned_expr(expr));
 275         if (ret)
 276                 return ret;
 277 
 278         ret = get_container_name_helper(get_assigned_expr(container),
 279                                         get_assigned_expr(expr));
 280         if (ret)
 281                 return ret;
 282 
 283         return NULL;
 284 }
 285 
 286 static bool is_fn_ptr(struct expression *expr)
 287 {
 288         struct symbol *type;
 289 
 290         if (!expr)
 291                 return false;
 292         if (expr->type != EXPR_SYMBOL && expr->type != EXPR_DEREF)
 293                 return false;
 294 
 295         type = get_type(expr);
 296         if (!type || type->type != SYM_PTR)
 297                 return false;
 298         type = get_real_base_type(type);
 299         if (!type || type->type != SYM_FN)
 300                 return false;
 301         return true;
 302 }
 303 
 304 static void match_call(struct expression *call)
 305 {