From e6f997e51d66d6321881648fc8050c02cbd4c605 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Fri, 15 Jun 2012 13:01:57 +0300 Subject: [PATCH] buf_size: if the member size is not known then store that in the DB The thought here is that some drivers allocate a buffer in the module_init() and it's always the same size. The problem is that we were only storing the size if it was known, and not if it was unknown. So it created a problem that sometimes we thought we knew the buffer size but actually we didn't. Signed-off-by: Dan Carpenter --- smatch_buf_size.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/smatch_buf_size.c b/smatch_buf_size.c index 230dc472..51638c5f 100644 --- a/smatch_buf_size.c +++ b/smatch_buf_size.c @@ -358,6 +358,22 @@ static void match_array_assignment(struct expression *expr) set_state_expr(my_size_id, left, alloc_state_num(array_size)); } +static void info_record_alloction(struct expression *buffer, struct expression *size) +{ + char *member; + long long val; + + if (!option_info) + return; + member = get_member_name(buffer); + if (!member) + return; + if (!get_implied_value(size, &val)) + val = -1; + sm_msg("info: '%s' allocated_buf_size %lld", member, val); + free_string(member); +} + static void match_alloc(const char *fn, struct expression *expr, void *_size_arg) { int size_arg = PTR_INT(_size_arg); @@ -367,19 +383,12 @@ static void match_alloc(const char *fn, struct expression *expr, void *_size_arg right = strip_expr(expr->right); arg = get_argument_from_call_expr(right->args, size_arg); + + info_record_alloction(expr->left, arg); + if (!get_implied_value(arg, &bytes)) return; - set_state_expr(my_size_id, expr->left, alloc_state_num(bytes)); - - if (option_info) { - char *member = get_member_name(expr->left); - - if (member) - sm_msg("info: '%s' allocated_buf_size %lld", - member, bytes); - free_string(member); - } } static void match_calloc(const char *fn, struct expression *expr, void *unused) -- 2.11.4.GIT