From 6e6e7c83eac7c04b7e97e788b44591b832e0f08e Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 13 Jun 2012 11:43:02 +0300 Subject: [PATCH] buf_size: make get_stored_size_bytes() a separate function This is useful on its own because converting from bytes to elements and back introduces rounding errors. Signed-off-by: Dan Carpenter --- smatch_buf_size.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/smatch_buf_size.c b/smatch_buf_size.c index 5a9546cd..52b7b935 100644 --- a/smatch_buf_size.c +++ b/smatch_buf_size.c @@ -183,14 +183,10 @@ static int get_size_from_initializer(struct expression *expr) return get_initializer_size(expr->symbol->initializer) * cast_ratio; } -static int get_stored_size(struct expression *expr) +static int get_stored_size_bytes(struct expression *expr) { struct sm_state *sm, *tmp; - float cast_ratio; int max = 0; - int ret; - - cast_ratio = get_cast_ratio(expr); sm = get_sm_state_expr(my_size_id, expr); if (!sm) @@ -201,8 +197,19 @@ static int get_stored_size(struct expression *expr) max = PTR_INT(tmp->state->data); } END_FOR_EACH_PTR(tmp); - ret = bytes_to_elements(expr, max); - return ret * cast_ratio; + return max; +} + +static int get_stored_size(struct expression *expr) +{ + float cast_ratio; + int size; + + cast_ratio = get_cast_ratio(expr); + + size = get_stored_size_bytes(expr); + size = bytes_to_elements(expr, size); + return size * cast_ratio; } static int get_size_from_strlen(struct expression *expr) -- 2.11.4.GIT