From a2e641c62361148532d59f5a4559b393996eb833 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 8 Nov 2012 17:18:50 +0300 Subject: [PATCH] sval: fix cast_rl() some more... There was a cut and paste bug when we tried to do a set_max it actually set the min. Also if we set the maximum, we should as well set the minimum to zero. Signed-off-by: Dan Carpenter --- smatch_ranges.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/smatch_ranges.c b/smatch_ranges.c index 8d36cd13..b1e9be50 100644 --- a/smatch_ranges.c +++ b/smatch_ranges.c @@ -661,11 +661,18 @@ struct range_list_sval *cast_rl(struct range_list_sval *rl, struct symbol *type) set_min = 1; FOR_EACH_PTR(rl, tmp) { - if (sval_cmp_t(type, tmp->max, sval_type_min(type)) < 0) + sval_t min, max; + + min = tmp->min; + max = tmp->max; + + if (sval_cmp_t(type, max, sval_type_min(type)) < 0) continue; - if (sval_cmp_t(type, tmp->min, sval_type_max(type)) > 0) + if (sval_cmp_t(type, min, sval_type_max(type)) > 0) continue; - new = alloc_range_sval(sval_cast(tmp->min, type), sval_cast(tmp->max, type)); + if (sval_cmp_val(min, 0) < 0 && type_unsigned(type)) + min.value = 0; + new = alloc_range_sval(sval_cast(min, type), sval_cast(max, type)); add_ptr_list(&ret, new); } END_FOR_EACH_PTR(tmp); @@ -678,7 +685,7 @@ struct range_list_sval *cast_rl(struct range_list_sval *rl, struct symbol *type) } if (set_max) { tmp = last_ptr_list((struct ptr_list *)ret); - tmp->min = sval_type_max(type); + tmp->max = sval_type_max(type); } return ret; -- 2.11.4.GIT