Print this page
11972 resync smatch
@@ -586,10 +586,13 @@
run_sql(db_buf_size_callback, NULL,
"select value from return_states where type=%d and %s",
BUF_SIZE, sql_filter);
if (!buf_size_recipe || strcmp(buf_size_recipe, "invalid") == 0)
return NULL;
+ /* Known sizes should be handled in smatch_buf_size.c */
+ if (!strchr(buf_size_recipe, '$'))
+ return NULL;
return swap_format(expr, buf_size_recipe);
}
static void match_call_assignment(struct expression *expr)
{
@@ -599,58 +602,33 @@
if (!sname)
return;
set_state_expr(my_id, expr->left, alloc_state_sname(sname));
}
-static void match_returns_call(int return_id, char *return_ranges, struct expression *call)
+const char *get_allocation_math(struct expression *expr)
{
- char *sname;
-
- sname = get_allocation_recipe_from_call(call);
- if (option_debug)
- sm_msg("sname = %s", sname);
- if (!sname)
- return;
-
- sql_insert_return_states(return_id, return_ranges, BUF_SIZE, -1, "",
- sname);
-}
-
-static void print_returned_allocations(int return_id, char *return_ranges, struct expression *expr)
-{
struct expression *tmp;
struct smatch_state *state;
- struct symbol *sym;
- char *name;
int cnt = 0;
expr = strip_expr(expr);
while ((tmp = get_assigned_expr(expr))) {
if (cnt++ > 5) /* assignments to self cause infinite loops */
break;
expr = strip_expr(tmp);
}
if (!expr)
- return;
+ return NULL;
- if (expr->type == EXPR_CALL) {
- match_returns_call(return_id, return_ranges, expr);
- return;
- }
+ if (expr->type == EXPR_CALL)
+ return get_allocation_recipe_from_call(expr);
- name = expr_to_var_sym(expr, &sym);
- if (!name || !sym)
- goto free;
-
- state = get_state(my_id, name, sym);
+ state = get_state_expr(my_id, expr);
if (!state || !state->data)
- goto free;
+ return NULL;
- sql_insert_return_states(return_id, return_ranges, BUF_SIZE, -1, "",
- state->name);
-free:
- free_string(name);
+ return state->name;
}
void register_parse_call_math(int id)
{
int i;
@@ -661,8 +639,7 @@
for (i = 0; i < ARRAY_SIZE(alloc_functions); i++)
add_function_assign_hook(alloc_functions[i].func, &match_alloc,
INT_PTR(alloc_functions[i].param));
add_hook(&match_call_assignment, CALL_ASSIGNMENT_HOOK);
- add_split_return_callback(print_returned_allocations);
}