From f73044fad643305048ee4c105d5485782b651792 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 24 Mar 2016 15:20:47 +0300 Subject: [PATCH] buf_size: save size of fixed arrays that are returned If we return a known, fixed size then store that in the database. We were already storing it if the returned size depended on a parameter. Signed-off-by: Dan Carpenter --- smatch_buf_size.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/smatch_buf_size.c b/smatch_buf_size.c index be5b8131..45637040 100644 --- a/smatch_buf_size.c +++ b/smatch_buf_size.c @@ -774,6 +774,25 @@ static void struct_member_callback(struct expression *call, int param, char *pri sql_insert_caller_info(call, BUF_SIZE, param, printed_name, sm->state->name); } +/* + * This is slightly (very) weird because half of this stuff is handled in + * smatch_parse_call_math.c which is poorly named. But anyway, add some buf + * sizes here. + * + */ +static void print_returned_allocations(int return_id, char *return_ranges, struct expression *expr) +{ + char buf[16]; + int size; + + size = get_array_size_bytes(expr); + if (!size) + return; + + snprintf(buf, sizeof(buf), "%d", size); + sql_insert_return_states(return_id, return_ranges, BUF_SIZE, -1, "", buf); +} + void register_buf_size(int id) { my_size_id = id; @@ -782,6 +801,7 @@ void register_buf_size(int id) select_caller_info_hook(set_param_buf_size, BUF_SIZE); select_return_states_hook(BUF_SIZE, &db_returns_buf_size); + add_split_return_callback(print_returned_allocations); allocation_funcs = create_function_hashtable(100); add_allocation_function("malloc", &match_alloc, 0); -- 2.11.4.GIT