From 9a20e7b5f8133d6f961fe34619fb612062f20d65 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Fri, 22 Jun 2018 14:56:40 +0300 Subject: [PATCH] buf_size: fix recording global sizes The original code worked for things like "int array[10];" but it failed for places where the size was determined by the initializer like "int array[] = {1, 2, 3};". Signed-off-by: Dan Carpenter --- smatch_buf_size.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/smatch_buf_size.c b/smatch_buf_size.c index 32542b6e..df2670bf 100644 --- a/smatch_buf_size.c +++ b/smatch_buf_size.c @@ -855,8 +855,7 @@ static void print_returned_allocations(int return_id, char *return_ranges, struc static void record_global_size(struct symbol *sym) { - struct symbol *type; - int elements, bpe, bytes; + int bytes; char buf[16]; if (!sym->ident) @@ -866,13 +865,10 @@ static void record_global_size(struct symbol *sym) sym->ctype.modifiers & MOD_STATIC) return; - type = get_real_base_type(sym); - elements = get_real_array_size_from_type(type); - if (elements <= 0) + bytes = get_array_size_bytes(symbol_expression(sym)); + if (bytes <= 1) return; - type = get_real_base_type(type); - bpe = type_bytes(type); - bytes = elements * bpe; + snprintf(buf, sizeof(buf), "%d", bytes); sql_insert_data_info_var_sym(sym->ident->name, sym, BUF_SIZE, buf); } -- 2.11.4.GIT