Print this page
new smatch

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/smatch_parse_call_math.c
          +++ new/usr/src/tools/smatch/src/smatch_parse_call_math.c
↓ open down ↓ 580 lines elided ↑ open up ↑
 581  581                  snprintf(sql_filter, 1024, "function = '%s' and static = 0;",
 582  582                                  sym->ident->name);
 583  583          }
 584  584  
 585  585          buf_size_recipe = NULL;
 586  586          run_sql(db_buf_size_callback, NULL,
 587  587                  "select value from return_states where type=%d and %s",
 588  588                  BUF_SIZE, sql_filter);
 589  589          if (!buf_size_recipe || strcmp(buf_size_recipe, "invalid") == 0)
 590  590                  return NULL;
      591 +        /* Known sizes should be handled in smatch_buf_size.c */
      592 +        if (!strchr(buf_size_recipe, '$'))
      593 +                return NULL;
 591  594          return swap_format(expr, buf_size_recipe);
 592  595  }
 593  596  
 594  597  static void match_call_assignment(struct expression *expr)
 595  598  {
 596  599          char *sname;
 597  600  
 598  601          sname = get_allocation_recipe_from_call(expr->right);
 599  602          if (!sname)
 600  603                  return;
 601  604          set_state_expr(my_id, expr->left, alloc_state_sname(sname));
 602  605  }
 603  606  
 604      -static void match_returns_call(int return_id, char *return_ranges, struct expression *call)
      607 +const char *get_allocation_math(struct expression *expr)
 605  608  {
 606      -        char *sname;
 607      -
 608      -        sname = get_allocation_recipe_from_call(call);
 609      -        if (option_debug)
 610      -                sm_msg("sname = %s", sname);
 611      -        if (!sname)
 612      -                return;
 613      -
 614      -        sql_insert_return_states(return_id, return_ranges, BUF_SIZE, -1, "",
 615      -                        sname);
 616      -}
 617      -
 618      -static void print_returned_allocations(int return_id, char *return_ranges, struct expression *expr)
 619      -{
 620  609          struct expression *tmp;
 621  610          struct smatch_state *state;
 622      -        struct symbol *sym;
 623      -        char *name;
 624  611          int cnt = 0;
 625  612  
 626  613          expr = strip_expr(expr);
 627  614          while ((tmp = get_assigned_expr(expr))) {
 628  615                  if (cnt++ > 5)  /* assignments to self cause infinite loops */
 629  616                          break;
 630  617                  expr = strip_expr(tmp);
 631  618          }
 632  619          if (!expr)
 633      -                return;
      620 +                return NULL;
 634  621  
 635      -        if (expr->type == EXPR_CALL) {
 636      -                match_returns_call(return_id, return_ranges, expr);
 637      -                return;
 638      -        }
      622 +        if (expr->type == EXPR_CALL)
      623 +                return get_allocation_recipe_from_call(expr);
 639  624  
 640      -        name = expr_to_var_sym(expr, &sym);
 641      -        if (!name || !sym)
 642      -                goto free;
 643      -
 644      -        state = get_state(my_id, name, sym);
      625 +        state = get_state_expr(my_id, expr);
 645  626          if (!state || !state->data)
 646      -                goto free;
      627 +                return NULL;
 647  628  
 648      -        sql_insert_return_states(return_id, return_ranges, BUF_SIZE, -1, "",
 649      -                        state->name);
 650      -free:
 651      -        free_string(name);
      629 +        return state->name;
 652  630  }
 653  631  
 654  632  void register_parse_call_math(int id)
 655  633  {
 656  634          int i;
 657  635  
 658  636          my_id = id;
 659  637  
 660  638          set_dynamic_states(my_id);
 661  639  
 662  640          for (i = 0; i < ARRAY_SIZE(alloc_functions); i++)
 663  641                  add_function_assign_hook(alloc_functions[i].func, &match_alloc,
 664  642                                           INT_PTR(alloc_functions[i].param));
 665  643          add_hook(&match_call_assignment, CALL_ASSIGNMENT_HOOK);
 666      -        add_split_return_callback(print_returned_allocations);
 667  644  }
 668  645  
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX